@devries-cameron20 / t3code Mirror · read-only / commits / 25aa9fc4e4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

fix(shared): preview addresses containing another URL open instead of searching (#17943)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Maxwell Young committed Oct 19, 2026 at 17:56 UTC 25aa9fc4e44954f7319375cc92f9b1278dfd1a14
2 files changed +11 -2
packages/shared/src/preview.test.ts
+8
@@ -64,6 +64,14 @@ describe("previewPdfAssetUrl", () => {
64 });
65
66 describe("resolveAddressBarInput", () => {
67 + it.each([
68 + ["localhost:3000/?next=https://example.com", "http://localhost:3000/?next=https://example.com"],
69 + ["127.0.0.1:3000/#https://example.com", "http://127.0.0.1:3000/#https://example.com"],
70 + ["example.com/https://example.org", "https://example.com/https://example.org"],
71 + ])("opens the outer address when it contains another URL: %s", (input, expected) => {
72 + expect(resolveAddressBarInput(input)).toBe(expected);
73 + });
74 +
75 it("opens what users type as addresses", () => {
76 expect(resolveAddressBarInput("localhost:5173")).toBe("http://localhost:5173/");
77 expect(resolveAddressBarInput("127.0.0.1:3000/path")).toBe("http://127.0.0.1:3000/path");
packages/shared/src/preview.ts
+3 -2
@@ -78,6 +78,7 @@ function previewUrlProtocol(rawUrl: string): string | undefined {
78 const SEARCH_URL = "https://duckduckgo.com/?q=";
79 const ADDRESS_HOST_PATTERN = /^(?:localhost|\d{1,3}(?:\.\d{1,3}){3}|\[[\da-f:.]+\])$/i;
80 const BARE_HOST_PORT_PATTERN = /^[^/?#:@]+:\d+(?:[/?#]|$)/;
81 +const URL_SCHEME_WITH_AUTHORITY_PATTERN = /^[a-z][a-z\d+.-]*:\/\//i;
82 const KNOWN_NON_WEB_SCHEMES: ReadonlySet<string> = new Set([
83 "about:",
84 "blob:",
@@ -97,7 +98,7 @@ const KNOWN_NON_WEB_SCHEMES: ReadonlySet<string> = new Set([
98
99 export function resolveAddressBarInput(rawInput: string): string {
100 const trimmed = rawInput.trim();
100 - if (/^[a-z][a-z\d+.-]*:\/\//i.test(trimmed) || trimmed.length === 0)
101 + if (URL_SCHEME_WITH_AUTHORITY_PATTERN.test(trimmed) || trimmed.length === 0)
102 return normalizePreviewUrl(trimmed);
103 if (!/\s/.test(trimmed)) {
104 // `mailto:x` or `data:...` is an explicit scheme; `example.com:8080` or
@@ -135,7 +136,7 @@ export function normalizePreviewUrl(rawUrl: string): string {
136 throw new PreviewUrlNormalizationError({ inputLength: rawUrl.length, reason: "empty" });
137 }
138 const useHttp = LOOPBACK_PREFIX_PATTERN.test(trimmed);
138 - const candidate = trimmed.includes("://")
139 + const candidate = URL_SCHEME_WITH_AUTHORITY_PATTERN.test(trimmed)
140 ? trimmed
141 : `${useHttp ? "http" : "https"}://${trimmed}`;
142 let parsed: URL;