Skip to content

Commit

Permalink
Merge pull request brave#13916 from brave/fix/13906
Browse files Browse the repository at this point in the history
Fix discrepancy between node url.parse and muon.url.parse
  • Loading branch information
diracdeltas committed May 2, 2018
2 parents ca83ee3 + ec32d00 commit 4ae26c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,12 @@ const UrlUtil = {
// parsed.origin is specific to muon.url.parse
if (parsed.origin !== undefined) {
if (parsed.protocol === 'about:') {
return [parsed.protocol, parsed.path].join('')
return [parsed.protocol, parsed.path.replace(/\/.*/, '')].join('')
}
return parsed.origin.replace(/\/+$/, '')
}
if (parsed.host && parsed.protocol) {
// parsed.slashes is specific to node's url.parse
return parsed.slashes ? [parsed.protocol, parsed.host].join('//') : [parsed.protocol, parsed.host].join('')
}
return null
Expand Down
10 changes: 7 additions & 3 deletions test/unit/lib/urlutilTestComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ module.exports = {

'isFileType': {
'relative file': (test) => {
test.equal(urlUtil().isFileType('/file/abc/test.pdf', 'pdf'), true)
test.equal(urlUtil().isFileType('file:///file/abc/test.pdf', 'pdf'), true)
},
'relative path': (test) => {
test.equal(urlUtil().isFileType('/file/abc/test', 'pdf'), false)
test.equal(urlUtil().isFileType('file:///file/abc/test', 'pdf'), false)
},
'JPG URL': (test) => {
test.equal(urlUtil().isFileType('http://example.com/test/ABC.JPG?a=b#test', 'jpg'), true)
Expand Down Expand Up @@ -365,7 +365,7 @@ module.exports = {
test.strictEqual(urlUtil().getOrigin('https://abc.bing.com'), 'https://abc.bing.com')
},
'gets URL origin for url with port': (test) => {
test.strictEqual(urlUtil().getOrigin('https://bing.com:443/?test=1#abc'), 'https://bing.com:443')
test.strictEqual(urlUtil().getOrigin('https://bing.com:8000/?test=1#abc'), 'https://bing.com:8000')
},
'gets URL origin for IP host': (test) => {
test.strictEqual(urlUtil().getOrigin('http://127.0.0.1:443/?test=1#abc'), 'http://127.0.0.1:443')
Expand All @@ -374,7 +374,11 @@ module.exports = {
test.strictEqual(urlUtil().getOrigin('about:preferences#abc'), 'about:preferences')
},
'gets URL origin for slashless protocol URL': (test) => {
test.strictEqual(urlUtil().getOrigin('about:test'), 'about:test')
test.strictEqual(urlUtil().getOrigin('about:test/'), 'about:test')
test.strictEqual(urlUtil().getOrigin('about:test/foo'), 'about:test')
test.strictEqual(urlUtil().getOrigin('about:test/foo/bar'), 'about:test')
test.strictEqual(urlUtil().getOrigin('about:test/foo/bar#baz'), 'about:test')
},
'returns null for invalid URL': (test) => {
test.strictEqual(urlUtil().getOrigin('abc'), null)
Expand Down

0 comments on commit 4ae26c3

Please sign in to comment.