Skip to content

Parse AdGuard #$# CSS injection as style/remove actions#686

Open
ryanbr wants to merge 1 commit into
masterfrom
adguard-css-injection
Open

Parse AdGuard #$# CSS injection as style/remove actions#686
ryanbr wants to merge 1 commit into
masterfrom
adguard-css-injection

Conversation

@ryanbr

@ryanbr ryanbr commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

AdGuard's #$# CSS-injection syntax (e.g. businesshemden.com#$#.mnd-cookie-modal { display: none !important; }) was rejected outright as UnsupportedSyntax. This routes it through the same brace-body parser added in #678 for the uBO/ABP ##selector { ... } form, producing a Style (or remove:Remove) action.

businesshemden.com#$#.mnd-cookie-modal { display: none !important; }
  →  Style(".mnd-cookie-modal" => "display: none !important;")

Details

  • The between_sharps.starts_with('$') branch now consumes the $ and sets a flag instead of erroring. The existing ? and leading-@ handlers then cover the extended #$?# and exception #@$# forms with no extra code.
  • A post-parse guard rejects any #$# rule that produced no action. This is the key safety check: ABP snippet injection also uses #$# but has no { ... } body (e.g. example.com#$#abort-on-property-read alert), and must stay unsupported rather than being misparsed as a plain CSS selector.
  • #%# / #@%# (AdGuard JS/scriptlet) remain unsupported — scope is limited to the CSS style/remove form.

Behavior change

Two existing assertions in tests/unit/lists.rs that expected #$# / #@$# to be UnsupportedSyntax are updated to expect successful parsing — this is the intended contract change.

Tests

cargo fmt --check clean; full lib suite passes under both default and css-validation features. Adds adguard_css_injection (style, multi-class selector, remove:, ABP-snippet rejection, generic rejection) and adguard_css_injection_extended (#$?#).


Supersedes #685 (that PR was opened from a fork, which makes the Performance CI step fail when it tries to post its results comment with a read-only token — no actual regression; all benchmark ratios were ≤ 1.00).

`#$#selector { ... }` (AdGuard CSS injection) was rejected outright as
unsupported syntax. Route it through the same brace-body parser used for
the uBO/ABP `##selector { ... }` form added in #678, producing a `Style`
or `remove:` action.

Only the style/remove form is handled — it always carries a `{ ... }`
body. ABP snippet injection also uses `#$#` but has no braces; those
produce no action and remain rejected. The extended `#$?#` and exception
`#@$#` forms fall out naturally via the existing `?`/`@` handlers.

@github-actions github-actions 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.

Rust Benchmark

Details
Benchmark suite Current: 77587df Previous: 5d182e5 Ratio
rule-match-browserlike/brave-list 2184625955 ns/iter (± 28173310) 2241363322 ns/iter (± 47317273) 0.97
rule-match-first-request/brave-list 1194826 ns/iter (± 15325) 1216052 ns/iter (± 6861) 0.98
blocker_new/brave-list 134582719 ns/iter (± 545998) 138839767 ns/iter (± 844690) 0.97
blocker_new/brave-list-deserialize 27992332 ns/iter (± 261528) 31752836 ns/iter (± 821884) 0.88
memory-usage-final/brave-list-initial 11355668 B/iter (± 0) 11355668 B/iter (± 0) 1
memory-usage-final/brave-list-1000-requests 2612449 B/iter (± 0) 2612449 B/iter (± 0) 1
memory-usage-max/brave-list-initial/max 63576475 B/iter (± 0) 63576475 B/iter (± 0) 1
memory-usage-alloc-count/brave-list-initial/alloc-count 859963 allocs/iter (± 0) 859963 allocs/iter (± 0) 1
memory-usage-alloc-count/brave-list-1000-requests/alloc-count 74018 allocs/iter (± 0) 74018 allocs/iter (± 0) 1
url_cosmetic_resources/brave-list 188858 ns/iter (± 652) 191870 ns/iter (± 955) 0.98
cosmetic-class-id-match/brave-list 3579896 ns/iter (± 966608) 3552152 ns/iter (± 986336) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

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