Normalize protocol-relative remote host input as https (#3971)

This commit is contained in:
Kriday Dave authored and GitHub committed 2026-07-17 18:59:42 +02:00
1 parent 4804a9824f
commit c49d424e3a
2 files changed
+68 -4

No files matched your search

+64
View File
@@ -59,6 +59,70 @@ describe("remote", () => {
});
});
it("treats a protocol-relative host as https", () => {
expect(
resolveRemotePairingTarget({
host: "//remote.example.com",
pairingCode: "pairing-token",
}),
).toEqual({
credential: "pairing-token",
httpBaseUrl: "https://remote.example.com/",
wsBaseUrl: "wss://remote.example.com/",
});
});
it("preserves the port when normalizing a protocol-relative host", () => {
expect(
resolveRemotePairingTarget({
host: "//remote.example.com:3000",
pairingCode: "pairing-token",
}),
).toEqual({
credential: "pairing-token",
httpBaseUrl: "https://remote.example.com:3000/",
wsBaseUrl: "wss://remote.example.com:3000/",
});
});
it("normalizes a protocol-relative host from a hosted pairing link", () => {
expect(
resolveRemotePairingTarget({
pairingUrl: "https://app.t3.codes/pair?host=%2F%2Fremote.example.com#token=pairing-token",
}),
).toEqual({
credential: "pairing-token",
httpBaseUrl: "https://remote.example.com/",
wsBaseUrl: "wss://remote.example.com/",
});
});
it("collapses extra leading slashes instead of producing an empty host", () => {
expect(
resolveRemotePairingTarget({
host: "///example.com",
pairingCode: "pairing-token",
}),
).toEqual({
credential: "pairing-token",
httpBaseUrl: "https://example.com/",
wsBaseUrl: "wss://example.com/",
});
});
it("does not double-prepend https when the host already carries a scheme", () => {
expect(
resolveRemotePairingTarget({
host: "//https://example.com",
pairingCode: "pairing-token",
}),
).toEqual({
credential: "pairing-token",
httpBaseUrl: "https://example.com/",
wsBaseUrl: "wss://example.com/",
});
});
it("preserves host ports when normalizing a bare host input", () => {
expect(
resolveRemotePairingTarget({
+4 -4
View File
@@ -81,10 +81,10 @@ const normalizeRemoteBaseUrl = (
throw new RemoteBackendUrlMissingError();
}
const normalizedInput =
/^[a-zA-Z][a-zA-Z\d+-]*:\/\//.test(trimmed) || trimmed.startsWith("//")
? trimmed
: `https://${trimmed}`;
const withoutLeadingSlashes = trimmed.replace(/^\/+/, "");
const normalizedInput = /^[a-zA-Z][a-zA-Z\d+-]*:\/\//.test(withoutLeadingSlashes)
? withoutLeadingSlashes
: `https://${withoutLeadingSlashes}`;
let url: URL;
try {
url = new URL(normalizedInput);