From 64439189ebc0dae1b8c635832239b99aadbb0616 Mon Sep 17 00:00:00 2001 From: yan Date: Fri, 19 May 2017 16:52:21 -0700 Subject: [PATCH 1/2] fix autosuggest error on file:/// URLs fix #8967 --- app/common/lib/suggestion.js | 4 ++-- test/unit/app/common/lib/suggestionTest.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/common/lib/suggestion.js b/app/common/lib/suggestion.js index 093273750a..518b6b7348 100644 --- a/app/common/lib/suggestion.js +++ b/app/common/lib/suggestion.js @@ -234,8 +234,8 @@ const getSortByDomain = (userInputLower, userInputHost) => { // any count or frequency calculation. // Note that for parsed URLs that are not complete, the pathname contains // what the user is entering as the host and the host is null. - const host1 = s1.parsedUrl.host || s1.parsedUrl.pathname - const host2 = s2.parsedUrl.host || s2.parsedUrl.pathname + const host1 = s1.parsedUrl.host || s1.parsedUrl.pathname || s1.location || '' + const host2 = s2.parsedUrl.host || s2.parsedUrl.pathname || s2.location || '' let pos1 = host1.indexOf(userInputHost) let pos2 = host2.indexOf(userInputHost) diff --git a/test/unit/app/common/lib/suggestionTest.js b/test/unit/app/common/lib/suggestionTest.js index 1faf67ad6c..a773cae2a0 100644 --- a/test/unit/app/common/lib/suggestionTest.js +++ b/test/unit/app/common/lib/suggestionTest.js @@ -250,6 +250,9 @@ describe('suggestion unit tests', function () { it('simple domain gets matched higher', function () { assert(this.sort('https://www.google.com', 'https://www.google.com/extra') < 0) }) + it('does not throw error for file:// URL', function () { + assert(this.sort('https://google.com', 'file://') < 0) + }) }) describe('getSortForSuggestions', function () { describe('with url entered as path', function () { From a430d6a05a8b4431238f0c89a827e8e06b1b65ff Mon Sep 17 00:00:00 2001 From: yan Date: Fri, 19 May 2017 18:04:44 -0700 Subject: [PATCH 2/2] fix noscript exception handling on file:/// URLs fix #8947 --- js/state/contentSettings.js | 10 ++++++++-- test/bravery-components/noScriptTest.js | 20 ++++++++++++++++++++ test/fixtures/noscript2.html | 8 ++++++++ test/fixtures/noscript2.js | 1 + 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/noscript2.html create mode 100644 test/fixtures/noscript2.js diff --git a/js/state/contentSettings.js b/js/state/contentSettings.js index e89f44fbbf..21c54f3602 100644 --- a/js/state/contentSettings.js +++ b/js/state/contentSettings.js @@ -22,12 +22,18 @@ const net = require('net') // backward compatibility with appState siteSettings const parseSiteSettingsPattern = (pattern) => { + if (pattern === 'file:///') { + return 'file:///*' + } let normalizedPattern = pattern.replace('https?', 'https') let parsed = urlParse(normalizedPattern) if (net.isIP(parsed.hostname)) { return parsed.host - } else { + } else if (parsed.host) { return '[*.]' + parsed.host + } else { + // Probably won't match anything. Fail closed. + return pattern } } @@ -237,7 +243,7 @@ const siteSettingsToContentSettings = (currentSiteSettings, defaultContentSettin noScriptExceptions.forEach((value, origin) => { if (value === false) { contentSettings = addContentSettings(contentSettings, 'javascript', - primaryPattern, origin, 'block') + primaryPattern, origin === 'file:///' ? 'file:///*' : origin, 'block') } }) } else if (noScriptExceptions && noScriptExceptions.size) { diff --git a/test/bravery-components/noScriptTest.js b/test/bravery-components/noScriptTest.js index 01b3aa4cf9..f1aa342ebc 100644 --- a/test/bravery-components/noScriptTest.js +++ b/test/bravery-components/noScriptTest.js @@ -78,6 +78,26 @@ describe('noscript info', function () { .loadUrl(this.url) .waitForTextValue(result, '2') }) + + it('can allow scripts on a file:// URL without allowing all scripts', function * () { + const fileUrl = Brave.fixtureUrl('noscript2.html') + yield this.app.client + .tabByIndex(0) + .loadUrl(fileUrl) + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible(noScriptNavButton) + .click(noScriptNavButton) + .waitForVisible(noScriptAllowTempButton) + .click(noScriptAllowTempButton) + .tabByIndex(0) + .loadUrl(fileUrl) + .waitForTextValue(result, 'scripts running') + .windowByUrl(Brave.browserWindowUrl) + .tabByIndex(0) + .loadUrl(this.url) + .windowByUrl(Brave.browserWindowUrl) + .waitForVisible(noScriptNavButton) + }) }) describe('noscript', function () { diff --git a/test/fixtures/noscript2.html b/test/fixtures/noscript2.html new file mode 100644 index 0000000000..3f53f11b37 --- /dev/null +++ b/test/fixtures/noscript2.html @@ -0,0 +1,8 @@ + +
+ +