feat(adblock): support domains-format blocklist sources (issue #213) - #222
Merged
Merged
Conversation
added 3 commits
September 24, 2026 08:49
Hosts-format parsing silently dropped bare-domain lines, so lists like anti-AD's domains.txt fetched 'successfully' with 0 rules and blocking never engaged — worse than an error because nothing surfaced it. - AdBlockSource gains an explicit `format` field (hosts | domains), chosen at add time; no runtime sniffing. #[serde(default)] = Hosts, so legacy adblock.json needs no migration (always serialized per the issue #202 lesson). - New parse_domains_blocklist reader: trim, skip blanks/# comments, lowercase + validate via the existing whitelist domain rules. The hosts path now also counts ParseResult.errors (previously discarded silently). - Anti-silent-failure contract in fetch_and_cache_source: 0 rules + malformed lines → hard failure (old cache kept, last_error points at the format setting); errors >= 10 and > 5% of kept rules → rules go live AND last_error carries an advisory warning. - Cache stays canonical hosts text, so the DNS engine / overlap report paths are untouched. - UI: Format dropdown on the add-source form (shared by bulk add), format shown in the source card meta line, copy updated. Tests: 8 new backend tests (domains reader, threshold boundaries, end-to-end domains fetch, loud 0-rule failure, warning path, serde back-compat), 1 new frontend test, existing assertions updated.
) CI clippy runs with --workspace, which compiles mhost-storage's lib tests — the sample_source fixture there was missed in 3d52e43 (local clippy without --workspace only covered the mhost package). Verified locally with cargo clippy/test --workspace --all-targets --all-features.
This was referenced Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Closes #213(跟踪 #130、#198)。
fetch_and_cache_source用 mhost-hosts 的Parser::parse解析上游 blocklist,parse_line要求首 token 必须是 IP —— 裸域名行被静默丢弃。anti-AD domains 版 / oisd 等「一行一个域名」的源会解析出 0 条规则且不报任何错,屏蔽完全不生效,属于静默失败。方案
显式
format字段,不做运行时嗅探:AdBlockSource新增format: BlocklistFormat(hosts|domains),#[serde(default)]默认hosts,旧adblock.json零迁移;字段无条件序列化(issue AdBlock error banner false positive: last_error serialization mismatch (undefined vs null) #202 教训)。domains走轻量 reader(trim → 跳过空行/#注释(含行内)→ 复用validate_whitelist_domain校验 + 小写化);hosts 路径顺带统计ParseResult.errors(此前被静默丢弃)。last_error提示检查 format 设置;last_error写告警(UI badge 可见)。0.0.0.0 domainhosts 文本),DNS 引擎 / overlap 报告 /classify_rules路径零改动;[Perf] ad-block cache 改为纯域名列表,跳过 hosts parser round-trip + ASCII lowercase 快路径 #198 的 cache 纯域名化重审留给后续。验收对照(issue 四条)
fetch_and_cache_source_domains_format_parses_bare_domains(rule_count 正确、缓存为 canonical hosts 文本);dig冒烟留手工验证last_error+ UI badge:fetch_and_cache_source_warns_when_error_lines_exceed_threshold明确不做
set_ad_block_source_format编辑命令(无 edit-source IPC 先例,改格式 = 删除重加,可后续单独提)测试
cargo fmt --all -- --check✓ /cargo clippy --all-targets --all-features -- -D warnings✓cargo test --all-features:mhost-core 51 ✓(+3:serde roundtrip、wire 格式、legacy 文档默认 Hosts)、主 crate 213 ✓(+8:domains reader 正/负路径、阈值边界、端到端、硬失败、告警)pnpm test336 ✓(+1:Format 下拉透传)、pnpm build✓