Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bat.js fix (fix for installing content blocking rules multiple times) #779

Merged
merged 9 commits into from May 8, 2024

Conversation

jaceklyp
Copy link
Contributor

Task/Issue URL: https://app.asana.com/0/1177771139624306/1205259925028360/f
iOS PR: todo
macOS PR: todo
What kind of version bump will this require?: Patch
CC: @mallexxx

Steps to test this PR:

  1. See main task

Internal references:

Software Engineering Expectations
Technical Design Template

@jaceklyp jaceklyp requested a review from bwaresiak April 12, 2024 08:47
self.add(ruleList)
guard contentRuleLists[.local(identifier)] == nil else {
assertionFailure("Local content rule list already installed: \(contentRuleLists[.local(identifier)]!)")
return
Copy link
Collaborator

@bwaresiak bwaresiak Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a problem.

I believe above implementation makes an implicit assumption: that every different rule lists set must have different identifier. This is not true, and it is also not something that is either expected on WebKit level.

The the scenario:

  1. Search for something -> navigate to vendor A. As a result we apply local rule list with "TemporaryAttributed" id, that contains exception for vendor A.
  2. Go back to results -> navigate to vendor B. At this point we want to replace rules tailored for vendor A, with the ones for vendor B, but both rules share the same identifier - "TemporaryAttributed".

It means in case identifiers clash (one is already installed), we need to remove the old rules first, and just then install the new ones.

We most likely should have a test case for this as it is basically a border condition of this API.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -36,6 +36,7 @@ extension OSLog {
}()

public enum Categories: String, CaseIterable {
case contentBlocking = "Content Blocking"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the same name as in macOS app repo will shows "Ambiguous use of 'contentBlocking" when I drop BSK into macOS project.

@bwaresiak
Copy link
Collaborator

bwaresiak commented Apr 29, 2024

I've tested this, and I believe it solves the problem. Still to be honest I'm concerned if there is anything else we might've missed. The overall side-effect driven nature of this code makes it quite tricky to follow or to foresee the possible issues - like the one we are solving here.

I don't think we have a good unit test suite for this, would be good to add something that:

  • Reproduces the problems we are solving here (not unloading old rule list, lack of access to up to date value in the code that listens for changes).
  • Tests the API of UserContentController.

@mallexxx mallexxx added the merge on approval This PR can be merged by the reviewer once approved label Apr 30, 2024
@mallexxx mallexxx assigned jaceklyp and unassigned bwaresiak Apr 30, 2024
Copy link

github-actions bot commented May 8, 2024

This PR has been inactive for more than 7 days and will be automatically closed 7 days from now.

@github-actions github-actions bot added the stale label May 8, 2024
@jaceklyp jaceklyp merged commit e328091 into main May 8, 2024
7 checks passed
@jaceklyp jaceklyp deleted the jacek/batjs-fix branch May 8, 2024 14:09
samsymons added a commit that referenced this pull request May 10, 2024
* main:
  Enable gzip compression for Sync PATCH payloads (#803)
  autofill: send current language in runtime config (#808)
  Password manager survey update (#811)
  on iOS allow bookmarks in top hits (#812)
  Rename tests to avoid conflicts (#813)
  Bat.js fix (fix for installing content blocking rules multiple times) (#779)
  Pixels automatic naming prefixing fixed (#810)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge on approval This PR can be merged by the reviewer once approved stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants