Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Fix problems with file:/// URLs #8969

Merged
merged 2 commits into from
May 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/common/lib/suggestion.js
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 8 additions & 2 deletions js/state/contentSettings.js
Original file line number Diff line number Diff line change
@@ -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) {
20 changes: 20 additions & 0 deletions test/bravery-components/noScriptTest.js
Original file line number Diff line number Diff line change
@@ -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 () {
8 changes: 8 additions & 0 deletions test/fixtures/noscript2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<body>
<div id='result'></div>
<script>
var result = document.getElementById('result')
result.innerText = 'scripts running'
</script>
<script src='noscript2.js' />
</body>
1 change: 1 addition & 0 deletions test/fixtures/noscript2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(1)
3 changes: 3 additions & 0 deletions test/unit/app/common/lib/suggestionTest.js
Original file line number Diff line number Diff line change
@@ -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 () {