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 21, 12:15 UTC
fix(shared): use HTTP for schemeless loopback previews (#29710)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Dias committed
Nov 15, 2026 at 01:43 UTC
137a8691384817e4c2e65f16ec8777e7ff0fb1fc
2 files changed
+16
-3
packages/shared/src/preview.test.ts
+10
@@ -149,6 +149,16 @@ describe("resolveSearchUrlTemplate", () => {
149
});
150
151
describe("normalizePreviewUrl", () => {
152
+ it.each([
153
+ ["127.0.0.2:3000/path", "http://127.0.0.2:3000/path"],
154
+ ["127.255.255.254:443/path", "http://127.255.255.254:443/path"],
155
+ ["0x7f.0.0.2:3000", "http://127.0.0.2:3000/"],
156
+ ["127.0.0.2.example.com:3000", "https://127.0.0.2.example.com:3000/"],
157
+ ["https://127.0.0.2:80/path", "https://127.0.0.2:80/path"],
158
+ ])("infers the scheme for loopback-looking %s", (input, expected) => {
159
+ expect(normalizePreviewUrl(input)).toBe(expected);
160
+ });
161
+
162
it("tells agents how to open a blank tab and which URLs are accepted", () => {
163
expect(() => normalizePreviewUrl("about:blank")).toThrow(
164
/preview_open, omit url when creating a new tab[^.]*blank tab/i,
packages/shared/src/preview.ts
+6
-3
@@ -194,9 +194,8 @@ export function normalizePreviewUrl(rawUrl: string): string {
194
});
195
}
196
const useHttp = LOOPBACK_PREFIX_PATTERN.test(trimmed);
197
- const candidate = URL_SCHEME_WITH_AUTHORITY_PATTERN.test(trimmed)
198
- ? trimmed
199
- : `${useHttp ? "http" : "https"}://${trimmed}`;
197
+ const hasExplicitScheme = URL_SCHEME_WITH_AUTHORITY_PATTERN.test(trimmed);
198
+ const candidate = hasExplicitScheme ? trimmed : `${useHttp ? "http" : "https"}://${trimmed}`;
199
let parsed: URL;
200
try {
201
parsed = new URL(candidate);
@@ -215,5 +214,9 @@ export function normalizePreviewUrl(rawUrl: string): string {
214
protocol: parsed.protocol,
215
});
216
}
217
+ // Re-parse rather than swap the protocol so an explicit :443 survives as a non-default HTTP port.
218
+ if (!hasExplicitScheme && !useHttp && isLocalLoopbackHost(parsed.hostname)) {
219
+ return new URL(`http://${trimmed}`).href;
220
+ }
221
return parsed.href;
222
}