Skip to content

Commit

Permalink
fix: optimize mayContainUnhandledIpfsProtocol
Browse files Browse the repository at this point in the history
This mostly means that we ignore XHR requests.
  • Loading branch information
lidel committed Oct 8, 2017
1 parent 7d3a5e0 commit 85f7af3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 1 addition & 3 deletions add-on/src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ function normalizedWebPlusRequest (request) {
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
// TODO: add checkbox under experiments
return request.url.includes('%3A%2F')
return request.type === 'main_frame' && request.url.includes('%3A%2F')
}

function unhandledIpfsPath (requestUrl) {
Expand Down
6 changes: 5 additions & 1 deletion test/unit/01-onBeforeRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var sandbox

const url2request = (string) => {
return {url: string}
return {url: string, type: 'main_frame'}
}

describe('onBeforeRequest', function () {
Expand Down Expand Up @@ -173,5 +173,9 @@ describe('onBeforeRequest', function () {
const request = url2request('https://duckduckgo.com/?q=foo%3A%2Fbar%3FargTest%23hashTest&foo=bar')
should.not.exist(onBeforeRequest(request))
})
it('should not be normalized if request.type != main_frame', function () {
const xhrRequest = {url: 'https://duckduckgo.com/?q=ipfs%3A%2FQmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR%3FargTest%23hashTest&foo=bar', type: 'xmlhttprequest'}
should.not.exist(onBeforeRequest(xhrRequest))
})
})
})

0 comments on commit 85f7af3

Please sign in to comment.