Skip to content

Commit

Permalink
Fix FirefoxDriver's parsing of IPv6 hostports when setting proxy conf…
Browse files Browse the repository at this point in the history
…iguration.
  • Loading branch information
juangj committed Apr 13, 2016
1 parent 6435986 commit 5d1741b
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions javascript/firefox-driver/js/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,35 @@ fxdriver.proxy.ProxyConfig;
fxdriver.proxy.LOG_ = fxdriver.logging.getLogger('fxdriver.proxy');


/**
* Splits a hostport, e.g., 'www.example.com:80' into host and port.
* @param {string} hostport A hostport.
* @return {{host: string, port: ?number}} A host and port. If no port is
* present in the argument hostport, port is null.
* @private
*/
fxdriver.proxy.splitHostPort_ = function(hostport) {
var colonIndex = hostport.lastIndexOf(':');
if (colonIndex < 0) {
return {host: hostport, port: null};
}
var secondColonIndex = hostport.indexOf(':');
if (secondColonIndex != colonIndex && !hostport.includes('[')) {
// The hostport contains multiple colons, but no part of it is bracketed,
// e.g., '2001:4860:4860::8888'. Treat it as an IPv6 literal with no port.
return {host: hostport, port: null};
}

var host = hostport.slice(0, colonIndex);
// Strip brackets from bracketed IPv6 hosts, e.g., '[::1]'.
if (host.startsWith('[') && host.endsWith(']')) {
host = host.slice(1, -1);
}
var portStr = hostport.slice(colonIndex + 1);
return {host: host, port: parseInt(portStr, 10)};
};


/**
* Set a specific proxy preference.
*
Expand All @@ -57,10 +86,12 @@ fxdriver.proxy.setProxyPreference_ = function(prefs, type, setting) {
if (!setting) {
return;
}
var hostPort = setting.split(':');
prefs.setCharPref('network.proxy.' + type, hostPort[0]);
if (hostPort.length > 1) {
prefs.setIntPref('network.proxy.' + type + '_port', parseInt(hostPort[1]));
var hostAndPort = fxdriver.proxy.splitHostPort_(setting);
var host = hostAndPort.host;
var port = hostAndPort.port;
prefs.setCharPref('network.proxy.' + type, host);
if (port != null) {
prefs.setIntPref('network.proxy.' + type + '_port', port);
}
};

Expand Down

0 comments on commit 5d1741b

Please sign in to comment.