Assignment used as a condition
high
A single = inside an if condition assigns instead of compares. The condition is then simply the assigned value, so the branch fires for every request.
Why it matters
if (host = "intranet.corp.example") overwrites host and evaluates to the non-empty
string, which is truthy. Every request takes that branch. The error is invisible in a
quick read because = and == look alike. The same applies to while and ternary
conditions.
How to fix
Use == (or === for strict comparison) in conditions.
Examples
Bad
function FindProxyForURL(url, host) {
if (host = "intranet.corp.example") {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (host == "intranet.corp.example") {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checker