Skip to content

Fix mixed own and descendant text matching - #319

Merged
facelessuser merged 2 commits into
facelessuser:mainfrom
JackyHsu-X:fix/mixed-contains-text-scopes
Oct 19, 2026
Merged

facelessuser merged 2 commits into
facelessuser:mainfrom
JackyHsu-X:fix/mixed-contains-text-scopes

Conversation

@JackyHsu-X

Copy link
Copy Markdown
Contributor

Combining :-soup-contains() and :-soup-contains-own() in one compound selector reuses the first condition's text for both scopes. For <div>own text<span>child text</span></div>, both selectors below should match, but neither does:

div:-soup-contains("child text"):-soup-contains-own("own text")
div:-soup-contains-own("own text"):-soup-contains("child text")

The shared value can also produce false positives: :-soup-contains("child text"):-soup-contains-own("c") matches even though c only occurs in a descendant.

Cache descendant text and direct text nodes separately, computing each only when needed. Add regressions for both orders, alternating conditions, alternative search terms, text-node boundaries, empty patterns, and nested selectors. The regressions use all three HTML parsers with caching enabled and disabled.

Validation on Windows / Python 3.12.8: full suite 419 passed, 12 subtests passed, 100% statement coverage; Ruff and mypy pass. The new regressions expose 10 failing subcases before the fix. An independent Beautiful Soup text oracle passes 2,704 comparisons across four parsers and detects a mismatch with the original method.

@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: css-custom CSS custom selectors. C: css-matching Related to CSS matching. C: docs Related to documentation. C: source Related to source code. C: tests Related to testing. labels Oct 18, 2026
Comment thread docs/src/markdown/about/changelog.md Resolved
@facelessuser

Copy link
Copy Markdown
Owner

@gir-bot lgtm

@gir-bot gir-bot added S: approved The pull request is ready to be merged. and removed S: needs-review Needs to be reviewed and/or approved. labels Oct 19, 2026
@facelessuser
facelessuser merged commit 084e370 into facelessuser:main Oct 19, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: css-custom CSS custom selectors. C: css-matching Related to CSS matching. C: docs Related to documentation. C: source Related to source code. C: tests Related to testing. S: approved The pull request is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants