Skip to content

Read $~document as every type but pages in filter lists - #305

Merged
egoist merged 1 commit into
egoist:mainfrom
kevin9327:fix/adblock-not-document
Nov 3, 2026
Merged

egoist merged 1 commit into
egoist:mainfrom
kevin9327:fix/adblock-not-document

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Problem

In internal/adblock, the document/doc option ignores a leading ~. $~document means "not pages" in Adblock Plus and uBlock Origin syntax, but Convert read it as $document:

Filter Before Expected
||cdn.example^$~document blocks with resource-type: ["document"], so the pages of cdn.example themselves blocks what is loaded from cdn.example, not its pages
@@||cdn.example^$~doc ignore-previous-rules with if-domain: ["*cdn.example"], so every block on those pages is undone an exception for the subresources from cdn.example only

The exception case is the more harmful one: an exception that a list wrote for loads becomes a page-wide allowlist.

Fix

The document/doc case now applies only without ~. A negated one falls through to the typeNames case like ~script does: document is added to notTypes and subtracted from the default subresource types.

Tests

Two cases added to TestConvertNetwork (not document, exception not of pages). Both fail on main with the "Before" output above and pass with the fix. go test ./internal/adblock and go vet ./internal/adblock pass, gofmt is 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.

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)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T01:13:58.655240Z d0baf92 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@egoist
egoist merged commit d1cd4fe into egoist:main Nov 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants