Skip to content

Commit 3508d1f

Browse files
committed
fix(mv3): 🐛 Bad regexSubstituition fixed
1 parent 42f1e31 commit 3508d1f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

add-on/src/lib/redirect-handler/blockOrObserve.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function constructRegexFilter ({ originUrl, redirectUrl }: redirectHandlerInput)
8888
// that ends up with capturing all urls which we do not want.
8989
if (regexFilter === `^https?\\:\\/${regexEnding}`) {
9090
const subdomain = new URL(originUrl).hostname
91-
regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${regexEnding}}`
91+
regexFilter = `^https?\\:\\/\\/${escapeURLRegex(subdomain)}${regexEnding}`
9292
regexSubstitution = regexSubstitution.replace('\\1', `/${subdomain}\\1`)
9393
}
9494

test/functional/lib/redirect-handler/blockOrObserve.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,25 @@ describe('lib/redirect-handler/blockOrObserve', () => {
103103
expect(action).to.deep.equal({ type: 'redirect', redirect: { "regexSubstitution": "http://localhost:8080\\1" } })
104104
expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/ipfs\\.io((?:[^\\.]|$).*)$'))
105105
})
106+
107+
it('Should add redirect for local gateway where originUrl is similar to redirectUrl', () => {
108+
addRuleToDynamicRuleSet({
109+
originUrl: 'https://docs.ipfs.tech',
110+
redirectUrl: 'http://localhost:8080/ipns/docs.ipfs.tech'
111+
})
112+
expect(browserMock.declarativeNetRequest.updateDynamicRules.called).to.be.true
113+
const [{ addRules, removeRuleIds }] = browserMock.declarativeNetRequest.updateDynamicRules.firstCall.args
114+
expect(removeRuleIds).to.deep.equal([])
115+
expect(addRules).to.have.lengthOf(1)
116+
const [{ id, priority, action, condition }] = addRules
117+
expect(id).to.be.a('number')
118+
expect(priority).to.equal(1)
119+
expect(action).to.deep.equal({
120+
type: 'redirect', redirect: {
121+
"regexSubstitution": "http://localhost:8080/ipns/docs.ipfs.tech\\1"
122+
}
123+
})
124+
expect(condition).to.deep.equal(dynamicRulesConditions('^https?\\:\\/\\/docs\\.ipfs\\.tech((?:[^\\.]|$).*)$'))
125+
})
106126
})
107127
})

0 commit comments

Comments
 (0)