diff --git a/js/lib/urlutil.js b/js/lib/urlutil.js index ccd775e9c5a..3b6fd64a693 100644 --- a/js/lib/urlutil.js +++ b/js/lib/urlutil.js @@ -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 diff --git a/test/unit/lib/urlutilTestComponents.js b/test/unit/lib/urlutilTestComponents.js index dc797f708b9..55dd829f862 100644 --- a/test/unit/lib/urlutilTestComponents.js +++ b/test/unit/lib/urlutilTestComponents.js @@ -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) @@ -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') @@ -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)