From 13213724b036140a95ad9116bc80a015066e5358 Mon Sep 17 00:00:00 2001 From: "Kirill A. Shutemov" Date: Tue, 21 Feb 2017 02:05:54 +0300 Subject: [PATCH 1/3] PAC: fix isPlainHostName() Fix isPlainHostName() implementation and add test-case for it. Signed-off-by: Kirill A. Shutemov --- qutebrowser/javascript/pac_utils.js | 2 +- tests/unit/browser/webkit/network/test_pac.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/qutebrowser/javascript/pac_utils.js b/qutebrowser/javascript/pac_utils.js index a6102df9f..b4540c18a 100644 --- a/qutebrowser/javascript/pac_utils.js +++ b/qutebrowser/javascript/pac_utils.js @@ -78,7 +78,7 @@ function isInNet(ipaddr, pattern, maskstr) { } function isPlainHostName(host) { - return (host.search('\\\\.') == -1); + return (host.search('\\.') == -1); } function isResolvable(host) { diff --git a/tests/unit/browser/webkit/network/test_pac.py b/tests/unit/browser/webkit/network/test_pac.py index dc9229dbf..e52b4e7ec 100644 --- a/tests/unit/browser/webkit/network/test_pac.py +++ b/tests/unit/browser/webkit/network/test_pac.py @@ -109,6 +109,15 @@ def test_myIpAddress(): _pac_equality_test("isResolvable(myIpAddress())", "true") +@pytest.mark.parametrize("host, expected", [ + ("example", "true"), + ("example.com", "false"), + ("www.example.com", "false"), +]) +def test_isPlainHostName(host, expected): + _pac_equality_test("isPlainHostName('{}')".format(host), expected) + + def test_proxyBindings(): _pac_equality_test("JSON.stringify(ProxyConfig.bindings)", "'{}'") From ac3c8bb319c789d981b65d97df1e6959023a4534 Mon Sep 17 00:00:00 2001 From: "Kirill A. Shutemov" Date: Tue, 21 Feb 2017 15:23:27 +0300 Subject: [PATCH 2/3] pac_utils.js: remove excessive escaping Looks like the implementation was derived from Mozilla's nsProxyAutoConfig.js, which is evaluated twice. It requires double escaping. In our case excessive escaping is harmful. In particular it makes ip-matching regexp in isInNet() invalid and makes it really slow as we go to dnsResolve() all the time, even when it's not needed. Signed-off-by: Kirill A. Shutemov --- qutebrowser/javascript/pac_utils.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qutebrowser/javascript/pac_utils.js b/qutebrowser/javascript/pac_utils.js index b4540c18a..0aba4c070 100644 --- a/qutebrowser/javascript/pac_utils.js +++ b/qutebrowser/javascript/pac_utils.js @@ -61,7 +61,7 @@ function convert_addr(ipchars) { } function isInNet(ipaddr, pattern, maskstr) { - var test = /^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/ + var test = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ .exec(ipaddr); if (test == null) { ipaddr = dnsResolve(ipaddr); @@ -92,9 +92,9 @@ function localHostOrDomainIs(host, hostdom) { } function shExpMatch(url, pattern) { - pattern = pattern.replace(/\\./g, '\\\\.'); - pattern = pattern.replace(/\\*/g, '.*'); - pattern = pattern.replace(/\\?/g, '.'); + pattern = pattern.replace(/\./g, '\\.'); + pattern = pattern.replace(/\*/g, '.*'); + pattern = pattern.replace(/\?/g, '.'); var newRe = new RegExp('^'+pattern+'$'); return newRe.test(url); } From d6e4344f65a5d5a3d80085e9705edfb089652488 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 25 Feb 2017 17:53:39 +0100 Subject: [PATCH 3/3] Update authors --- README.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.asciidoc b/README.asciidoc index 326223511..67444c9fb 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -226,6 +226,7 @@ Contributors, sorted by the number of commits in descending order: * Lucas Hoffmann * Link * Larry Hynes +* Kirill A. Shutemov * Johannes Altmanninger * Jeremy Kaplan * Ismail @@ -265,7 +266,6 @@ Contributors, sorted by the number of commits in descending order: * Matthias Lisin * Marcel Schilling * Lazlow Carmichael -* Kirill A. Shutemov * Kevin Wang * Ján Kobezda * Johannes Martinsson