From 7d1f88f391d7ffa62446e00494b468228325fe09 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Tue, 12 Mar 2019 19:08:44 +0000 Subject: [PATCH] Bug 1532990 handle default port better for proxy.settings r=zombie Differential Revision: https://phabricator.services.mozilla.com/D22297 --HG-- extra : moz-landing-system : lando --- .../components/extensions/parent/ext-proxy.js | 4 +- .../test/xpcshell/test_ext_proxy_config.js | 38 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/toolkit/components/extensions/parent/ext-proxy.js b/toolkit/components/extensions/parent/ext-proxy.js index b219d186ca84..8fb347275fab 100644 --- a/toolkit/components/extensions/parent/ext-proxy.js +++ b/toolkit/components/extensions/parent/ext-proxy.js @@ -73,7 +73,9 @@ ExtensionPreferencesManager.addSetting("proxy.settings", { if (value[prop]) { let url = new URL(`http://${value[prop]}`); prefs[`network.proxy.${prop}`] = url.hostname; - let port = parseInt(url.port, 10) || DEFAULT_PORTS.get(prop); + // Only fall back to defaults if no port provided. + let [, rawPort] = value[prop].split(":"); + let port = parseInt(rawPort, 10) || DEFAULT_PORTS.get(prop); prefs[`network.proxy.${prop}_port`] = port; } else { prefs[`network.proxy.${prop}`] = undefined; diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js index 178dda72990a..edfce28b5690 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_config.js @@ -282,7 +282,6 @@ add_task(async function test_browser_settings() { } ); - await testProxy( { proxyType: "manual", @@ -319,6 +318,43 @@ add_task(async function test_browser_settings() { } ); + + await testProxy( + { + proxyType: "manual", + http: "http://www.mozilla.org:80", + ftp: "ftp://www.mozilla.org:80", + ssl: "https://www.mozilla.org:80", + socks: "mozilla.org:80", + socksVersion: 4, + passthrough: ".mozilla.org", + }, + { + "network.proxy.type": proxySvc.PROXYCONFIG_MANUAL, + "network.proxy.http": "www.mozilla.org", + "network.proxy.http_port": 80, + "network.proxy.share_proxy_settings": false, + "network.proxy.ftp": "www.mozilla.org", + "network.proxy.ftp_port": 80, + "network.proxy.ssl": "www.mozilla.org", + "network.proxy.ssl_port": 80, + "network.proxy.socks": "mozilla.org", + "network.proxy.socks_port": 80, + "network.proxy.socks_version": 4, + "network.proxy.no_proxies_on": ".mozilla.org", + }, + { + proxyType: "manual", + http: "www.mozilla.org:80", + httpProxyAll: false, + ftp: "www.mozilla.org:80", + ssl: "www.mozilla.org:80", + socks: "mozilla.org:80", + socksVersion: 4, + passthrough: ".mozilla.org", + } + ); + // Test resetting values. await testProxy( {