From d025e0f92a99eee49ed332fccff2f0cbfa766739 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Mon, 12 Jan 2026 20:40:32 +0000 Subject: [PATCH] fix: replace regex with charCodeAt-based check Use character code comparisons instead of RegExp for link-local IPv6 detection. This avoids the overhead of regex compilation and matching while still correctly detecting the fe80::/10 range. Co-Authored-By: Claude Opus 4.5 --- src/js/node/_http_client.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/js/node/_http_client.ts b/src/js/node/_http_client.ts index 5d07ac6b65..86f4aa1cb3 100644 --- a/src/js/node/_http_client.ts +++ b/src/js/node/_http_client.ts @@ -502,8 +502,21 @@ function ClientRequest(input, options, cb) { // so we deprioritize them to avoid connection timeouts on VPN networks. // See: https://github.com/oven-sh/bun/issues/25619 const isLinkLocalIPv6 = (addr: string) => { - // fe80::/10 covers fe80:: through febf:: - return /^fe[89ab][0-9a-f]:/i.test(addr); + // fe80::/10 covers fe80:: through febf:: (first 10 bits are 1111111010) + // Check if address starts with fe8, fe9, fea, or feb (case-insensitive) + if (addr.length < 4) return false; + const c0 = addr.charCodeAt(0) | 0x20; // lowercase + const c1 = addr.charCodeAt(1) | 0x20; + const c2 = addr.charCodeAt(2) | 0x20; + const c3 = addr.charCodeAt(3); + // Check for 'fe[89ab]:' + return ( + c0 === 0x66 && + c1 === 0x65 && // 'fe' + (c2 === 0x38 || c2 === 0x39 || c2 === 0x61 || c2 === 0x62) && // '8', '9', 'a', 'b' + ((c3 >= 0x30 && c3 <= 0x39) || ((c3 | 0x20) >= 0x61 && (c3 | 0x20) <= 0x66)) && // hex digit + addr.charCodeAt(4) === 0x3a + ); // ':' }; let candidates = results.sort((a, b) => { const aIsLinkLocal = a.family === 6 && isLinkLocalIPv6(a.address);