From 56527f533f772c6cf1572bd9bcdd9cef72104c9e Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Mon, 18 Sep 2017 00:10:38 +0200 Subject: [PATCH] fix: more strict custom protocols https://github.com/ipfs/ipfs-companion/pull/283#issuecomment-330058239 --- add-on/src/lib/common.js | 24 +++-- test/unit/01-onBeforeRequest.test.js | 136 +++++++++------------------ 2 files changed, 58 insertions(+), 102 deletions(-) diff --git a/add-on/src/lib/common.js b/add-on/src/lib/common.js index 6d9a3236b..25d57d7be 100644 --- a/add-on/src/lib/common.js +++ b/add-on/src/lib/common.js @@ -96,7 +96,10 @@ function onBeforeRequest (request) { // handler for protocol_handlers from manifest.json if (webPlusProtocolRequest(request)) { // fix path passed via custom protocol - return normalizedWebPlusRequest(request) + const fix = normalizedWebPlusRequest(request) + if (fix) { + return fix + } } // handle redirects to custom gateway @@ -126,18 +129,21 @@ function pathAtPublicGw (path) { } function normalizedWebPlusRequest (request) { - let path = decodeURIComponent(new URL(request.url).pathname) - path = path.replace(/^\/web\+fs:[/]*/i, '/') // web+fs://ipfs/Qm → /ipfs/Qm - path = path.replace(/^\/web\+dweb:[/]*/i, '/') // web+dweb://ipfs/Qm → /ipfs/Qm - path = path.replace(/^\/web\+([^:]+):[/]*/i, '/$1/') // web+foo://Qm → /foo/Qm - path = path.replace(/^\/ip([^/]+)\/ip[^/]+\//, '/ip$1/') // /ipfs/ipfs/Qm → /ipfs/Qm - return { redirectUrl: pathAtPublicGw(path) } + const oldPath = decodeURIComponent(new URL(request.url).pathname) + let path = oldPath + path = path.replace(/^\/web\+dweb:\//i, '/') // web+dweb:/ipfs/Qm → /ipfs/Qm + path = path.replace(/^\/web\+ipfs:\/\//i, '/ipfs/') // web+ipfs://Qm → /ipfs/Qm + path = path.replace(/^\/web\+ipns:\/\//i, '/ipns/') // web+ipns://Qm → /ipns/Qm + if (oldPath !== path && window.IsIpfs.path(path)) { + return { redirectUrl: pathAtPublicGw(path) } + } + return null } // PROTOCOL HANDLERS: UNIVERSAL FALLBACK FOR UNHANDLED PROTOCOLS // =================================================================== -const unhandledIpfsRE = /=(?:web%2B|)(ipfs|ipns|fs|dweb)%3A(?:%2F|)(%2F[^&]+)/ +const unhandledIpfsRE = /=(?:web%2B|)(ipfs(?=%3A%2F%2F)|ipns(?=%3A%2F%2F)|dweb(?=%3A%2Fip[f|n]s))%3A(?:%2F%2F|%2F)([^&]+)/ function mayContainUnhandledIpfsProtocol (request) { // TODO: run only for google, bing, duckduckgo etc @@ -149,7 +155,7 @@ function unhandledIpfsPath (requestUrl) { const unhandled = requestUrl.match(unhandledIpfsRE) if (unhandled && unhandled.length > 1) { const unhandledProtocol = decodeURIComponent(unhandled[1]) - const unhandledPath = decodeURIComponent(unhandled[2]) + const unhandledPath = `/${decodeURIComponent(unhandled[2])}` return window.IsIpfs.path(unhandledPath) ? unhandledPath : `/${unhandledProtocol}${unhandledPath}` } return null diff --git a/test/unit/01-onBeforeRequest.test.js b/test/unit/01-onBeforeRequest.test.js index d6f4810a2..ccb294395 100644 --- a/test/unit/01-onBeforeRequest.test.js +++ b/test/unit/01-onBeforeRequest.test.js @@ -49,164 +49,114 @@ describe('onBeforeRequest', function () { }) describe('request made via "web+" handler from manifest.json/protocol_handlers', function () { - it('should be normalized if URI is web+ipfs:/{CID}', function () { - const request = url2request('https://ipfs.io/web%2Bipfs:/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + it('should not be normalized if URI is web+ipfs:/{CID}', function () { + const request = url2request('https://ipfs.io/web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is web+ipfs://{CID}', function () { - const request = url2request('https://ipfs.io/web%2Bipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + const request = url2request('https://ipfs.io/web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') }) - it('should be normalized if URI is web+ipns:/{foo}', function () { - const request = url2request('https://ipfs.io/web%2Bipns:/ipfs.io%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + it('should not be normalized if URI is web+ipns:/{foo}', function () { + const request = url2request('https://ipfs.io/web%2Bipns%3A%2Fipfs.io%3FargTest%23hashTest') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is web+ipns://{foo}', function () { - const request = url2request('https://ipfs.io/web%2Bipns://ipfs.io%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - }) - it('should be normalized if URI is web+fs:/ipfs/{CID}', function () { - const request = url2request('https://ipfs.io/web%2Bfs:/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - }) - it('should be normalized if URI is web+fs://ipfs/{CID}', function () { - const request = url2request('https://ipfs.io/web%2Bfs://ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') - }) - it('should be normalized if URI is web+fs:/ipns/{foo}', function () { - const request = url2request('https://ipfs.io/web%2Bfs:/ipns/ipfs.io%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') - }) - it('should be normalized if URI is web+fs://ipns/{foo}', function () { - const request = url2request('https://ipfs.io/web%2Bfs://ipns/ipfs.io%3FargTest%23hashTest') + const request = url2request('https://ipfs.io/web%2Bipns%3A%2F%2Fipfs.io%3FargTest%23hashTest') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') }) it('should be normalized if URI is web+dweb:/ipfs/{CID}', function () { - const request = url2request('https://ipfs.io/web%2Bdweb:/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + const request = url2request('https://ipfs.io/web%2Bdweb%3A%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') }) - it('should be normalized if URI is web+dweb://ipfs/{CID}', function () { - const request = url2request('https://ipfs.io/web%2Bdweb://ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + it('should not be normalized if URI is web+dweb://ipfs/{CID}', function () { + const request = url2request('https://ipfs.io/web%2Bdweb%3A%2F%2Fipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is web+dweb:/ipns/{foo}', function () { - const request = url2request('https://ipfs.io/web%2Bdweb:/ipns/ipfs.io%3FargTest%23hashTest') + const request = url2request('https://ipfs.io/web%2Bdweb%3A%2Fipns/ipfs.io%3FargTest%23hashTest') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') }) - it('should be normalized if URI is web+dweb://ipns/{foo}', function () { - const request = url2request('https://ipfs.io/web%2Bdweb://ipns/ipfs.io%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io?argTest#hashTest') + it('should not be normalized if URI is web+dweb://ipns/{foo}', function () { + const request = url2request('https://ipfs.io/web%2Bdweb%3A%2F%2Fipns/ipfs.io%3FargTest%23hashTest') + should.not.exist(onBeforeRequest(request)) }) - it('should be normalized if URI is web+{foo}:/bar', function () { - const request = url2request('https://ipfs.io/web%2Bfoo:/bar%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/foo/bar?argTest#hashTest') + it('should not be normalized if URI is web+{foo}:/bar', function () { + const request = url2request('https://ipfs.io/web%2Bfoo%3A%2Fbar%3FargTest%23hashTest') + should.not.exist(onBeforeRequest(request)) }) - it('should be normalized if URI is web+{foo}://bar', function () { - const request = url2request('https://ipfs.io/web%2Bfoo://bar%3FargTest%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/foo/bar?argTest#hashTest') + it('should not be normalized if URI is web+{foo}://bar', function () { + const request = url2request('https://ipfs.io/web%2Bfoo%3A%2F%2Fbar%3FargTest%23hashTest') + should.not.exist(onBeforeRequest(request)) }) }) - // TODO: add tests for unhandled protocol schemes: - // - google, duck duck go, bing, baidu, yandex - describe('unhandled custom protocol request', function () { - it('should be normalized if URI is ipfs:/{CID}', function () { + describe('catching unhandled custom protocol request', function () { + it('should not be normalized if URI is ipfs:/{CID}', function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is ipfs://{CID}', function () { const request = url2request('https://duckduckgo.com/?q=ipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') }) - it('should be normalized if URI is ipns:/{foo}', function () { + it('should not be normalized if URI is ipns:/{foo}', function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is ipns://{foo}', function () { const request = url2request('https://duckduckgo.com/?q=ipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') }) - it('should be normalized if URI is fs:/ipfs/{CID}', function () { - const request = url2request('https://duckduckgo.com/?q=fs%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is fs://ipfs/{CID}', function () { - const request = url2request('https://duckduckgo.com/?q=fs%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is fs:/ipns/{foo}', function () { - const request = url2request('https://duckduckgo.com/?q=fs%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is fs://ipns/{foo}', function () { - const request = url2request('https://duckduckgo.com/?q=fs%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - }) it('should be normalized if URI is dweb:/ipfs/{CID}', function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') }) - it('should be normalized if URI is dweb://ipfs/{CID}', function () { + it('should not be normalized if URI is dweb://ipfs/{CID}', function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is dweb:/ipns/{foo}', function () { - const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is dweb://ipns/{foo}', function () { const request = url2request('https://duckduckgo.com/?q=dweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') }) + it('should not be normalized if URI is dweb://ipns/{foo}', function () { + const request = url2request('https://duckduckgo.com/?q=dweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') + should.not.exist(onBeforeRequest(request)) + }) - it('should be normalized if URI is web+ipfs:/{CID}', function () { + it('should not be normalized if URI is web+ipfs:/{CID}', function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is web+ipfs://{CID}', function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipfs%3A%2F%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest') }) - it('should be normalized if URI is web+ipns:/{foo}', function () { + it('should not be normalized if URI is web+ipns:/{foo}', function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is web+ipns://{foo}', function () { const request = url2request('https://duckduckgo.com/?q=web%2Bipns%3A%2F%2Fipns.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hashTest') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipns.io/index.html?arg=foo&bar=buzz#hashTest') }) - it('should be normalized if URI is web+fs:/ipfs/{CID}', function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bfs%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is web+fs://ipfs/{CID}', function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bfs%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is web+fs:/ipns/{foo}', function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bfs%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is web+fs://ipns/{foo}', function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bfs%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - }) it('should be normalized if URI is web+dweb:/ipfs/{CID}', function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') }) - it('should be normalized if URI is web+dweb://ipfs/{CID}', function () { + it('should not be normalized if URI is web+dweb://ipfs/{CID}', function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipfs%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=software') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?arg=foo&bar=buzz#hash') + should.not.exist(onBeforeRequest(request)) }) it('should be normalized if URI is web+dweb:/ipns/{foo}', function () { - const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') - onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') - }) - it('should be normalized if URI is web+dweb://ipns/{foo}', function () { const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') onBeforeRequest(request).redirectUrl.should.equal('https://ipfs.io/ipns/ipfs.io/index.html?arg=foo&bar=buzz#hash') }) + it('should not be normalized if URI is web+dweb://ipns/{foo}', function () { + const request = url2request('https://duckduckgo.com/?q=web%2Bdweb%3A%2F%2Fipns%2Fipfs.io%2Findex.html%3Farg%3Dfoo%26bar%3Dbuzz%23hash&ia=web') + should.not.exist(onBeforeRequest(request)) + }) it('should not be normalized if disabled in Preferences', function () { state.catchUnhandledProtocols = false