Repository navigation
Read $~document as every type but pages in filter lists - #305
Conversation
A filter's ~document option was read as document, so ||cdn.example^$~document blocked the pages of cdn.example instead of what they load, and @@||cdn.example^$~doc became an exception for the whole page. ~document now subtracts the type as ~script does. Assisted-by: AI (Grok Bot)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0baf9294a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case except && (name == "elemhide" || name == "ehide" || name == "generichide" || name == "ghide" || name == "specifichide" || name == "shide"): | ||
| hiding = true | ||
| case name == "document" || name == "doc": | ||
| case (name == "document" || name == "doc") && !not: |
There was a problem hiding this comment.
Preserve child-frame matches when negating document
With a valid filter such as ||cdn.example^$subdocument,~document, this branch sends ~document to notTypes. Since subdocument was already translated to WebKit's document type with a child-frame context, the subsequent subtraction removes the only type and network drops the rule. A subdocument is an iframe, not a top-level page, so negating document should not remove the child-frame match.
Useful? React with 👍 / 👎.
Problem
In
internal/adblock, thedocument/docoption ignores a leading~.$~documentmeans "not pages" in Adblock Plus and uBlock Origin syntax, butConvertread it as$document:||cdn.example^$~documentresource-type: ["document"], so the pages of cdn.example themselves@@||cdn.example^$~docignore-previous-ruleswithif-domain: ["*cdn.example"], so every block on those pages is undoneThe exception case is the more harmful one: an exception that a list wrote for loads becomes a page-wide allowlist.
Fix
The
document/doccase now applies only without~. A negated one falls through to thetypeNamescase like~scriptdoes:documentis added tonotTypesand subtracted from the default subresource types.Tests
Two cases added to
TestConvertNetwork(not document,exception not of pages). Both fail onmainwith the "Before" output above and pass with the fix.go test ./internal/adblockandgo vet ./internal/adblockpass,gofmtis clean.AI assistance: I used an AI assistant to help find this and write the change; I checked the behavior and ran the tests above.