Repository navigation
fix(rules): read element-separated text in schema/rating-scope #739 - #748
Merged
Merged
Conversation
rating-scope searched `content.textContent`, which glues adjacent elements: `<h3>Customer rating</h3><p>5/5</p>` reads "Customer rating5/5", no word-bounded rating pattern matches, and the rule warned that a printed rating was not visible. Add getPageSeparatedText (content/text-content.ts): the body's getSeparatedText, whitespace collapsed, memoised per document. The rating check searches it next to the glued text, so more text can only clear the check, never trip it. #696 will reuse the same helper. kit-signature keeps the glued text: every bundled string that reads `text` is a substring with no word boundary, so gluing cannot change a verdict; a threat-intel test pins the glued/spaced pair. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
marked this pull request as ready for review
October 13, 2026 13:43
|
Reviewed the diff. The change is small, matches the stated scope, and I found nothing blocking.
Correctness: the reasoning that adding text can only clear the visibility check, never newly trip it, holds. The glued text is still searched, so nothing that passed before can warn. Leaving |
5 tasks done
nc9
added a commit
that referenced
this pull request
Oct 14, 2026
…mpty-body branch #739 Follow-up to the #748 review nits: say the per-document cache assumes a read-only DOM, and assert "" for a document with no body instead of only the return type. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
added a commit
that referenced
this pull request
Oct 14, 2026
…mpty-body branch #739 Follow-up to the #748 review nits: say the per-document cache assumes a read-only DOM, and assert "" for a document with no body instead of only the return type. Signed-off-by: Nik Cubrilovic <[email protected]>
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 #739.
What changed
schema/rating-scopesearchedctx.parsed.content.textContent, the body's.textContent, which glues adjacent elements.<h3>Customer rating</h3><p>5/5</p>readsCustomer rating5/5, so no word-bounded rating pattern matched there. With a whole-number rating (no decimal-value fallback), the rule then warned that a rating printed on the page was not visible.getPageSeparatedText(doc)inpackages/rules/src/content/text-content.ts. It is the body's existinggetSeparatedText(a space at every element boundary; scripts, styles,noscriptandtemplateskipped), with whitespace collapsed, memoised per parsed document in aWeakMap. This is the element-boundary helper integrity/brand-impersonation loses a signal without inter-element whitespace #696 will reuse.rating-scope:visibleTextsearches the separated text next to the glued text. Every visibility test asks whether a rating appears anywhere, so more text can only clear the check, never trip it. Nothing that passed before can warn.integrity/kit-signature: checked and unaffected, documented in code. It passes the glued text as the signaturetextcorpus. The only bundled signature (calendly-kit) reads text only through a case-insensitive substring with no word boundary, which gluing cannot change. Switching it to separated text would instead split a brand an author wrapped across inline elements (Cal<b>endly</b>). A new test inpackages/threat-intel/tests/signatures.test.tspins that the kit page and a legit Calendly page get identical matches with glued and spaced text. A comment at the call site says why the text stays glued.Acceptance criteria
schema/rating-scope:packages/rules/tests/glued-element-text.test.tshas four fixture pairs (block label then score, table row, label then count, inline spans), each passing both ways, plus a no-rating page that warns both ways. On main, the glued half of every pair warns; I checked that by swapping main'srating-scope.tsback in.integrity/kit-signatureis checked against a glued/spaced pair and documented as unaffected (above).getPageSeparatedText), built on the existinggetSeparatedText. No new extraction.Verification
bun test packages/rules/tests/glued-element-text.test.ts: 9 pass.bun test packages/threat-intel/tests/signatures.test.ts packages/rules/tests/schema-rating-scope.test.ts packages/rules/tests/integrity-intel.test.ts: 44 pass.bun test packages/rules/tests/rule-verdict-scope.test.ts: 340 pass.bun test packages/audit-engine/tests/template-fanout-parity-golden.test.ts: 53 pass.bun test packages/audit-engine/tests/streaming-rules-canonical-golden.test.ts: 1 pass, no re-pin.tsgo --noEmitinpackages/rulesandpackages/threat-intel: clean. oxlint is clean on the changed files. The oxfmt drift inrating-scope.tsandtext-content.tsis pre-existing on main.make validateindocs/: all checks passed.Agent skill
No change needed.