PAC-E004 · findproxyforurl-wrong-arity

FindProxyForURL does not take exactly two parameters

medium · Errors and robustness

Engines call FindProxyForURL(url, host). With one parameter the hostname is unavailable; with more than two the extra parameters are always undefined.

Why it matters

The engine always passes two arguments. A function declared with a single parameter has no way to read the hostname unless it parses url itself. Extra parameters are never filled and any logic based on them silently takes the undefined branch. Parameter names are free (see PAC-B002); the count is what matters.

How to fix

Declare the function as function FindProxyForURL(url, host).

Examples

Bad

function FindProxyForURL(url) {
  if (shExpMatch(url, "*.corp.example*")) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
Open bad example in checker

Good

function FindProxyForURL(url, host) {
  if (dnsDomainIs(host, ".corp.example")) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
Open good example in checker

Related rules

References