Skip to content

Commit ffdefd7

Browse files
authored
Fix SyntaxError caused by template literal mangling regex backslashes (#235)
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.
1 parent e37c557 commit ffdefd7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/pac_utils_dump.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ int main() {
1616
printf("// directly, so that the eval'd PAC sandbox can define its own\n");
1717
printf("// dnsResolve() / myIpAddress() in the same scope as the utility\n");
1818
printf("// functions — keeping DNS mocking correct via lexical scoping.\n");
19-
printf("const PAC_UTILS_JS = `\n");
19+
// String.raw preserves backslashes as-is, preventing the JS template
20+
// literal parser from mangling regex patterns like /\*/g → /*/g (invalid).
21+
printf("const PAC_UTILS_JS = String.raw`\n");
2022
printf("%s", pacUtils);
2123
printf("`;\n");
2224
return 0;

web/pac_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// directly, so that the eval'd PAC sandbox can define its own
66
// dnsResolve() / myIpAddress() in the same scope as the utility
77
// functions — keeping DNS mocking correct via lexical scoping.
8-
const PAC_UTILS_JS = `
8+
const PAC_UTILS_JS = String.raw`
99
function dnsDomainIs(host, domain) {
1010
return (host.length >= domain.length &&
1111
host.substring(host.length - domain.length) == domain);

0 commit comments

Comments
 (0)