Fix: disguised-ad-flag skips single card with content wrapper (#228 follow-up)#231
Merged
Merged
Conversation
…ollow-up) PR #230's `hasOtherCardSubtree` guard rejected any candidate enclosing a descendant outside the label's chain that carried both an image and an outgoing link. A common card layout — label as sibling to a single content wrapper that holds heading + image + link — tripped that guard, and the legitimate ad card escaped detection. Switch to counting *outermost* qualifying subtrees and reject only when two or more exist. Include the label's own containing chain in the count so a feed wrapper (label's card + sibling cards) still trips at >= 2, while a single card with stacked wrapper divs collapses to 1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Follow-up to #230 (review feedback from Unblocked bot).
PR #230's
hasOtherCardSubtreeguard rejected any candidate enclosing a descendant outside the label's chain that carried both an image and an outgoing link. A common card layout — label as a sibling to a single content wrapper that holds heading + image + link — tripped the guard, and the legitimate ad card escaped detection entirely.div.card-bodyis not the label, not contained by the label, and does not contain the label. It has both an<img>and an<a href>descendant → the pre-fix guard returnedtrue→isArticleShapedreturnedfalse→ the card was not hidden.Fix
Rename
hasOtherCardSubtree→hasMultipleCardSubtreesand require two or more outermost non-overlapping qualifying subtrees before rejecting. The label's own containing chain does count toward the total (thecandidate.contains(labelElement)skip is dropped), so a feed wrapper still trips at >= 2 (label's card + sibling cards), while a single card with one (or several stacked) content wrappers collapses to 1.Verifying #228 still holds
<shreddit-feed>with 3 ad-post cards, one momentarily headless: walking from the headless card's label reaches the feed; the feed encloses 3 outermost card subtrees (each card has img+a) → count >= 2 → feed wrapper is rejected, individual headed cards still match on their own walk-up.Test plan
bun run check— cleanbun run typecheck— cleanbun run knip— clean./node_modules/.bin/jest— 1918 tests passing, including:hides a single card whose content sits inside a wrapper divregression test indisguised-ad-flag.test.tsdisguised-ad-flag.property.test.tsasserting that a single card with N stacked wrapper divs is always hidden (N ∈ [1, 5])reddit.comwith the unpacked extension after merge🤖 Generated with Claude Code