Skip to content

Added parser for $to option in NetworkFilter.#701

Open
boocmp wants to merge 1 commit into
masterfrom
to_option_1
Open

Added parser for $to option in NetworkFilter.#701
boocmp wants to merge 1 commit into
masterfrom
to_option_1

Conversation

@boocmp

@boocmp boocmp commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Added support for parsing the $to option in network filters. Matching behavior remains unchanged.

@github-actions

Copy link
Copy Markdown

[puLL-Merge] - brave/adblock-rust@701

Description

Adds parsing/storage for $to= network filter option (destination hostname restrictions). Refactors domain-parsing logic into shared helpers parse_pipe_delimited_domains and hash_pipe_delimited_domains. Adds new flatbuffer fields opt_to_domains/opt_to_not_domains, bumps DAT version 5→6. Regenerates flatbuffer code from newer compiler (::flatbuffersflatbuffers, alloc:: → std). $to filters are parsed and stored only — not applied at match time (skipped in add_filter via has_to_option()).

Possible Issues

  • $to silently ignored at match time. NetworkRulesBuilder::add returns early on has_to_option(), dropping rule entirely. Filters with $to provide no filtering. Match tests confirm this (all matches_test assert false). If a rule uses only $to as a restriction on an otherwise-blocking rule, this weakens blocking vs. dropping the rule. Verify intent — could under-block. Comment says "for now," so presumably staged rollout.

  • DAT version bump correct but consumers with v5 caches must regenerate. Expected.

  • Regex-domain filter behavior: parse_pipe_delimited_domains drops /regex/ entries silently, errors only if all dropped (NoSupportedDomains). Matches existing domain= behavior. Consistent.

  • compute_filter_id now includes $to hashes — changes filter IDs for existing rules? No, only rules with $to set contribute new hasher writes; existing rules unaffected since opt_to_* are None. Test hash changes reflect the format version bump, not ID collisions.

Changes

src/data_format/mod.rs

  • Version 5→6.

src/filters/abstract_network.rs

  • Extract parse_pipe_delimited_domains helper. Add NetworkFilterOption::To. Parse to option. Wire unit test module.

src/filters/network.rs

  • Add opt_to_domains/opt_to_not_domains fields. Extract hash_pipe_delimited_domains (deduped shared logic). Handle To option. Add has_to_option(). Include $to hashes in compute_filter_id (+#[allow(clippy::too_many_arguments)]).

src/filters/fb_network_builder.rs

  • Serialize new fields. Early-return in add for $to filters.

src/flatbuffers/fb_network_filter.fbs + generated.rs

  • New opt_to_domains/opt_to_not_domains fields. Full regeneration with new flatbuffer compiler output style (unrelated churn: ::flatbuffersflatbuffers, alloc::→std types, unsafe fn→outer unsafe {} blocks).

tests/unit/

  • New abstract_network.rs helper tests. parses_to parse tests. Match tests asserting $to ignored. Updated hash constants + filter count (122996→123328).

Notes

  • Generated-file churn (.fbs regen) mixed with feature work makes review harder. Consider separating compiler-upgrade regen from feature commit in future.
  • Filter count delta (+332) suggests some $to rules previously rejected now parse. Confirm expected.
sequenceDiagram
    participant Src as filter line "$to=..."
    participant AN as abstract_network::parse_filter_options
    participant NF as NetworkFilter::parse
    participant FB as NetworkRulesBuilder::add
    participant Flat as fb_network_builder

    Src->>AN: parse options
    AN->>AN: parse_pipe_delimited_domains(value)
    AN-->>NF: NetworkFilterOption::To(domains)
    NF->>NF: hash_pipe_delimited_domains -> opt_to_domains / opt_to_not_domains
    NF-->>FB: NetworkFilter{ opt_to_* set }
    FB->>FB: has_to_option()?
    alt has $to
        FB-->>FB: early return (not indexed for matching)
    else no $to
        FB->>Flat: serialize + index
    end
    FB->>Flat: serialize opt_to_* fields (storage only)
Loading

Comment thread src/flatbuffers/fb_network_filter_generated.rs
Comment thread src/flatbuffers/fb_network_filter_generated.rs
Comment thread src/flatbuffers/fb_network_filter_generated.rs
Comment thread src/flatbuffers/fb_network_filter_generated.rs
Comment thread src/flatbuffers/fb_network_filter_generated.rs
Comment thread src/flatbuffers/fb_network_filter_generated.rs
@boocmp boocmp self-assigned this Jul 16, 2026

Copilot AI 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.

Pull request overview

This PR adds parsing and serialization support for the $to= option in network filters, while aiming to keep runtime matching behavior unchanged by not applying $to constraints during request evaluation.

Changes:

  • Added $to= parsing (pipe-delimited domain list with ~ negation) and stored the parsed data on NetworkFilter.
  • Extended the FlatBuffers schema/data format to persist $to domain restrictions and bumped ADBLOCK_RUST_DAT_VERSION.
  • Added/updated unit tests and adjusted engine serialization hash expectations to reflect the new data format.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/filters/network.rs Adds unit tests asserting $to= is parsed into opt_to_domains / opt_to_not_domains.
tests/unit/filters/network_matchers.rs Adds tests asserting $to-containing filters do not affect matching behavior.
tests/unit/filters/abstract_network.rs New unit tests for pipe-delimited domain parsing helper.
tests/unit/engine.rs Updates expected serialization hashes and network filter counts for the new format.
src/flatbuffers/fb_network_filter.fbs Adds opt_to_domains / opt_to_not_domains fields to the NetworkFilter FlatBuffer table.
src/flatbuffers/fb_network_filter_generated.rs Regenerates FlatBuffers bindings to include the new fields and other generator output changes.
src/filters/network.rs Stores $to domain restrictions on NetworkFilter, wires parsing, and includes them in filter ID computation.
src/filters/fb_network_builder.rs Serializes $to domain restrictions, and currently skips inserting $to filters into the engine.
src/filters/abstract_network.rs Introduces parse_pipe_delimited_domains and uses it for domain/from and new to options; wires unit tests.
src/data_format/mod.rs Bumps the persisted data format version from 5 to 6.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/flatbuffers/fb_network_filter_generated.rs
Comment thread src/flatbuffers/fb_network_filter_generated.rs Outdated
Comment thread src/filters/fb_network_builder.rs Outdated
Comment thread src/filters/network.rs Outdated

@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: 3f916d7 Previous: bd2f117 Ratio
rule-match-browserlike/brave-list 2242670735 ns/iter (± 17711909) 2381054868 ns/iter (± 34045922) 0.94
rule-match-first-request/brave-list 1363603 ns/iter (± 89562) 1472017 ns/iter (± 27538) 0.93
blocker_new/brave-list 114674686 ns/iter (± 2148085) 116855936 ns/iter (± 843156) 0.98
blocker_new/brave-list-deserialize 31095429 ns/iter (± 105372) 33093630 ns/iter (± 1471291) 0.94
memory-usage-final/brave-list-initial 9560898 B/iter (± 0) 9560762 B/iter (± 0) 1.00
memory-usage-final/brave-list-1000-requests 3157476 B/iter (± 0) 3157476 B/iter (± 0) 1
memory-usage-max/brave-list-initial/max 32069586 B/iter (± 0) 32069450 B/iter (± 0) 1.00
memory-usage-alloc-count/brave-list-initial/alloc-count 284056 allocs/iter (± 0) 282954 allocs/iter (± 0) 1.00
memory-usage-alloc-count/brave-list-1000-requests/alloc-count 80015 allocs/iter (± 0) 80015 allocs/iter (± 0) 1
url_cosmetic_resources/brave-list 184637 ns/iter (± 1941) 185445 ns/iter (± 1200) 1.00
cosmetic-class-id-match/brave-list 3219801 ns/iter (± 840237) 3228305 ns/iter (± 800958) 1.00

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

github-actions[bot]

This comment was marked as outdated.

@boocmp
boocmp marked this pull request as draft July 17, 2026 04:54
@boocmp
boocmp marked this pull request as ready for review July 17, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants