From 9fd7b293c43ab2593ac6238752e0ae7c971e0a04 Mon Sep 17 00:00:00 2001 From: Manu Garg Date: Mon, 9 Feb 2026 23:16:23 -0800 Subject: [PATCH] Fix SyntaxError caused by template literal mangling regex backslashes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A plain template literal processes escape sequences, turning /\*/g into /*/g and /\?/g into /?/g — both invalid regexes that cause eval() to throw "Invalid or unexpected token". Fix: use String.raw`...` in pac_utils_dump.c so the JS source is stored verbatim with all backslashes preserved. --- src/pac_utils_dump.c | 4 +++- web/pac_utils.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pac_utils_dump.c b/src/pac_utils_dump.c index cf748af..83217b7 100644 --- a/src/pac_utils_dump.c +++ b/src/pac_utils_dump.c @@ -16,7 +16,9 @@ int main() { printf("// directly, so that the eval'd PAC sandbox can define its own\n"); printf("// dnsResolve() / myIpAddress() in the same scope as the utility\n"); printf("// functions — keeping DNS mocking correct via lexical scoping.\n"); - printf("const PAC_UTILS_JS = `\n"); + // String.raw preserves backslashes as-is, preventing the JS template + // literal parser from mangling regex patterns like /\*/g → /*/g (invalid). + printf("const PAC_UTILS_JS = String.raw`\n"); printf("%s", pacUtils); printf("`;\n"); return 0; diff --git a/web/pac_utils.js b/web/pac_utils.js index a90864e..b87826b 100644 --- a/web/pac_utils.js +++ b/web/pac_utils.js @@ -5,7 +5,7 @@ // directly, so that the eval'd PAC sandbox can define its own // dnsResolve() / myIpAddress() in the same scope as the utility // functions — keeping DNS mocking correct via lexical scoping. -const PAC_UTILS_JS = ` +const PAC_UTILS_JS = String.raw` function dnsDomainIs(host, domain) { return (host.length >= domain.length && host.substring(host.length - domain.length) == domain);