Bitwise | or & used instead of || or &&
medium
A single | or & converts both operands to 32-bit integers. For booleans the result is accidentally right, but both sides are always evaluated and non-boolean operands produce 0, which silently drops the branch.
Why it matters
a | b evaluates both sides (no short-circuit), so a DNS call on the right-hand side runs
even when the left side already decided. The operands are coerced to integers: a string
such as shExpMatch(...) | "DIRECT" becomes 0 and the condition is never true. &
behaves correspondingly. The typo survives casual testing because true | false is 1,
which is truthy.
How to fix
Replace | with || and & with &&.
Examples
Bad
function FindProxyForURL(url, host) {
if (host == "a.corp.example" | host == "b.corp.example") {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (host == "a.corp.example" || host == "b.corp.example") {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerRelated rules
- Assignment used as a condition PAC-E009