Regular-expression syntax inside a shExpMatch pattern
medium
shExpMatch(host, "(www|mail).corp.example") works in Chromium, Firefox and pacparser only because their helper turns the glob into a JavaScript RegExp without escaping ( ) and |. That is an accident, not the PAC contract; Windows (WinHTTP) treats the characters literally and never matches.
Why it matters
The PAC specification defines shExpMatch as shell-style matching with * and ?. The
JavaScript helper library shared by Chromium, Firefox and pacparser escapes dots, rewrites
* and ? and then builds a RegExp, so alternation (a|b) and other regex syntax leak
through and work. Windows (WinHTTP) does not: in the lab on Windows 11 (2026-10-11) its
shExpMatch knew only * and ?, took [ ] + ( ) | { } $ as ordinary characters, and
gave ^ a special meaning of its own. shExpMatch("ab", "a|b") and
shExpMatch("abc", "[ab]bc") were false there, while shExpMatch("a+c", "a+c") was true. A
PAC relying on alternation therefore has an engine dependency that is invisible in browser
tests. Writing the alternatives as separate shExpMatch or host == clauses is portable and
no slower.
How to fix
Spell the alternatives out as separate conditions joined with ||.
Examples
Bad
function FindProxyForURL(url, host) {
if (shExpMatch(host, "(www|mail).corp.example")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (host == "www.corp.example" || host == "mail.corp.example") {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerEngine behaviour
| Engine | Behaviour | Source |
|---|---|---|
| chromium | shExpMatch converts the glob to a RegExp without escaping ( ) | ; regex alternation works. | code, verified 2026-10-04 · ref |
| firefox | Same helper-library approach (ascii_pac_utils.js); regex alternation works. | code, unverified |
| winhttp | Only * and ? are wildcards; [ ] + ( ) | { } $ are matched literally, so regex alternation never matches. A ^ in the pattern changes the match (shExpMatch("x^", "x^") is false). Matching is case-sensitive. | lab, verified 2026-10-11 |
The PAC functions this rule is about
shExpMatch(): Shell-glob match of str against pattern; * matches any sequence, ? one character. The whole string must match.
Related rules
- Path, port or query characters in a host pattern PAC-C003
- Pattern with leading and trailing * is a substring match PAC-X009