Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor inpage blocklist to avoid usage of regex (#8675)
## **Description** This PR fixes two bugs that occured as the result of using regex to identify URLs in our content script blocklist. The first issue is that we were only escaping the first `.` found in a URL when using the inpage blocklist. This meant that entries such as `ani.gamer.com.tw` would have their first period escaped for regex parsing, but subsequent periods were treated as regex wildcards. This could lead to and unintentionally matching on URLs such as `ani.gamerxcom.tw` etc. The second issue is that we were missing a leading anchor `^` in the regex expression. This means that we would block the domain if the matched string occurred anywhere in the URL. For an example, `https://google.com?search=uscourts.gov` would be a blocked domain since it ended in `uscourts.gov`. Adding the leading anchor addresses this so we only match the correct domain. To avoid future regex complexities, this code has been refactored to use built in javascript URL parsing instead. ## **Related issues** MetaMask/mobile-planning#1571 ## **Manual testing steps** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [ ] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [X] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [X] I’ve properly set the pull request status: - [X] In case it's not yet "ready for review", I've set it to "draft". - [X] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. Note: Issue with testing has been created here: #9009
- Loading branch information