Repository navigation
feat(rules): add content/unrendered-markup, literal markdown or escaped HTML in rendered copy - #217
Merged
Merged
Conversation
3 tasks done
nc9
force-pushed
the
feat/1352-content-unrendered-markup
branch
from
September 6, 2026 23:23
42311d5 to
9bef33a
Compare
added 5 commits
September 7, 2026 09:31
…caped HTML Detects literal markdown (emphasis, links, headings, fences) and visible escaped HTML or double-encoded entities in the text a visitor actually reads. Reads prose from the DOM with script-like AND code-like subtrees excluded, so a docs page displaying markdown source stays clean. That exclusion is the rule, not a refinement: <code>, <pre>, <samp>, <kbd>, <textarea>, plus whole-token syntax-highlighter classes and the data-language family. Precision work, measured against 88 real pages (1 residual, w3schools' HTML tutorial, which displays source in a bespoke div): - emphasis requires CommonMark flanking, so CLOUDFLARE_API_TOKEN, 2 * 3 and some_file_name.ts are not emphasis; the underscore form also requires a space inside, which silences __init__ and __main__ - a markdown link needs a URL-shaped target, so array[i](arg) is not a link - escaped tags must be lowercase (<Article> is a component name) and at least one must carry a closing form or a valued attribute (<meta name> in a sentence is documentation) - entities match a curated list, so Johnson&Johnson; is not an entity - visible backticks corroborate but never accuse on their own Regexes are kept linear with bounded, non-adjacent quantifiers and covered by adversarial 64 KB timing tests. Refs squirrelscan/repo#1352 Signed-off-by: Nik Cubrilovic <[email protected]>
Six findings from a fresh-eyes pass, in descending order of severity.
The heading and fence families were effectively dead on any real page.
collectTextExcluding emits its separator only for EXCLUDED subtrees, so sibling
blocks concatenate with nothing between them and a /m ^ anchor matched only at
offset 0 — which, on a page with a header, is never. Adds an optional isBoundary
predicate to collectTextExcluding (default undefined, so no existing caller
moves) and passes a block-tag predicate. Verified: <p>## Pricing</p> behind a
nav went from silent to reported, as did adjacent list items sharing emphasis.
`rest.includes("=")` called any prose equals sign an attribute, so
`if a<b then c=1>0 holds` was reported at fail. Replaced with a recognised
attribute-name allowlist, the same shape that already keeps Johnson&Johnson;
from reading as an entity. A path in angle brackets is no longer a closing tag.
The reported count, kind list and example included markdown-inline-code, which
the threshold excludes: a page with one bold phrase and five backtick spans
announced six occurrences at warn, and showed a backtick span as the example.
The headline now reports only the evidence that decided the status.
Also: the tag-name bound is derived from the tag sets rather than a literal
{0,9} that blockquote and figcaption already sat exactly on; the emphasis family
honours one match budget instead of one per pattern; a vouching tag past the cap
no longer drops the whole family; isCodeLikeElement makes one pass over
attributes rather than five (19.8ms -> 1.9ms per extraction on a 10k-element
DOM); bare "pre" is gone from the highlighter class tokens.
Tests: the eight "adversarial" fixtures carried a single trigger character each
and could not detect backtracking at all — a deliberately bad link pattern
measured 0.1ms on the old fixture and 5.2s on a dense one. Replaced with 18
dense-trigger fixtures at a 400ms budget, plus assertions that the scan cap
truncates rather than merely finishing fast. The golden pin now checks the
per-rule tally directly instead of inferring "all 500 are passes" from an
unmoved health score.
Re-smoked against 75 reachable real pages: 74 clean. The residual is w3schools'
HTML tutorial, which displays source in a bespoke div. One new false positive
the boundary work introduced (MDN renders a URL fragment on its own line) is
fixed by rejecting slug-shaped headings.
Two rule-count literals the first commit missed: README's per-category table and
the duplicate content card in docs/rules/seo. Both category tables now sum to
280.
Refs squirrelscan/repo#1352
Signed-off-by: Nik Cubrilovic <[email protected]>
Second review pass. Every finding reproduced before it was fixed. The boundary was emitted on ENTER only, which moved the gluing bug to the other edge rather than fixing it: `<h3>Price *</h3><a>terms* apply</a>` still read back as `*terms*`, emphasis present in neither element, and a split escaped tag reached `fail` on the same basis. collectTextExcluding now pushes a stack marker before a boundary element's children so the separator closes after them, and the escaped-tag pattern no longer accepts a newline inside an attribute list, which was the second way two blocks could assemble one tag. Making every block start a line gave the number sign a line start too, so `<th># of seats</th>` warned as a leaked heading. A single `#` now needs a capitalised word after it; `##` and deeper have no second reading and are taken as written, which also restores `## my-package` and `## getting-started` that the previous slug guard was silencing. The attribute allowlist had no legacy presentational names, so escaped table and email HTML - no closing tags, `align`/`bgcolor`/`valign` only - had nothing to vouch for it and passed clean. Added those, deliberately without single-letter SVG names, which would resurrect the `a<b then d=1>0` false positive. Also: sibling `<option>`s glued like `<li>`s, so option/optgroup/caption/legend/ menu join the block tags; the escaped-tag sample now leads with the tag that actually vouched rather than whichever bare mention came first, moved by index because moving it by value would delete its duplicates and undercount; and the `closing` helper moved above its callers, since a const arrow is not hoisted and packages/* is not linted. Tests: two of five boundary fixtures passed with the boundary deleted because they sat at the body's first byte. Replaced with fixtures that all follow chrome, plus five gluing fixtures that must stay clean and one proving a tag whole within a single block is still reported. Re-smoked against 85 real pages, all reachable: 83 clean, worst rule time 10ms. Both residuals are w3schools tutorials displaying HTML source in a bespoke div, the known and documented case. MDN's element pages are now clean. Refs squirrelscan/repo#1352 Signed-off-by: Nik Cubrilovic <[email protected]>
Rule solutions render in reports and on the docs site, so they are public copy, where the house style is a colon rather than an em-dash. Also corrects two comments that described the previous implementation: the attribute read is one pass now, and the escaped-tag sample is the vouching tag rather than the first. Refs squirrelscan/repo#1352 Signed-off-by: Nik Cubrilovic <[email protected]>
Rebase onto content/placeholder-text (#214). Three things needed a decision rather than a mechanical resolution. Both branches bumped the published counts 279 -> 280 with byte-identical edits, so git merged them as one change and no conflict was raised. The live loader now returns 281 rules and 20 content rules while every literal still said 280 and 19. Corrected across README, docs/index.mdx, docs/rules/index.mdx, docs/rules/seo/index.mdx and docs/agent-setup/index.mdx; both per-category tables and all four score-group card sets now sum to 281. Both branches also added the SAME optional isBoundary parameter to collectTextExcluding, independently. #214's version emits the separator on entering a matching element only, on the reasoning that the next block's own entry closes the previous one. That holds between two blocks, which is all placeholder-text needs, but not when a block is followed by inline content: `<h3>Price *</h3><a>terms* apply</a>` still reads back as `*terms*`, emphasis present in neither element. Kept the symmetric version, which satisfies both rules, and merged the two test suites into one describe block. That makes the extracted text carry a closing separator as well, so three exact-string expectations in placeholder-text.test.ts moved. Only the strings: each test still asserts what its name says, and every rule-outcome assertion in that suite is untouched and green. The golden gate now pins 99221 findings and 281 tally keys, both rules contributing 500 passing page checks to the 518-page fixture. Verified: packages/rules content suites 177 pass, packages/parser 41 pass, audit-engine golden 15 pass across six files, tsgo clean in parser, rules, audit-engine and apps/cli, root lint clean, docs check clean. Refs squirrelscan/repo#1352 Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
feat/1352-content-unrendered-markup
branch
from
September 6, 2026 23:31
9bef33a to
4d45119
Compare
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.
Refs squirrelscan/repo#1352
Summary
Adds
content/unrendered-markup, a per-page rule that detects markup which failed to render and leaked into the copy a visitor reads: literal markdown (emphasis, links, headings, fences), visible escaped HTML, and double-encoded entities.The rule reads decoded prose from the DOM, never raw HTML, with script-like and code-like subtrees excluded. Excluding those is the rule rather than a refinement, because a documentation site displaying markdown source is doing its job.
<code>,<pre>,<samp>,<kbd>and<textarea>come out, along with whole-token syntax-highlighter classes (highlight,hljs,shiki,chroma,codehilite,preformatted, anylanguage-*) and thedata-languageattribute family. Whole tokens, so ahighlight-boxcallout is still judged as prose.A note on the acceptance criteria. The issue says the rule registers in
loader.ts.loader.tsregisters namespaces, not rules; a new content rule is registered inpackages/rules/src/content/index.ts, which is whatloadAllRules()reads. The criterion's intent is met and noloader.tschange is needed. The issue also namesstripHtmlForText; that helper takes a string and cannot exclude<pre>/<code>, so the rule usescollectTextExcluding, the non-mutating DOM extraction thatcontent/mojibakeadopted for exactly this problem.A shared helper changed, and #214 changed it too.
collectTextExcludinggained an optional fourth parameter,isBoundary. Without it, sibling blocks concatenate with nothing between them,<p>a</p><p>b</p>reads back asab, and every line-anchored pattern here can only match at offset 0, which on a real page means never. The parameter defaults to undefined, so existing call sites are unchanged, and the 518-page canonical golden gate confirms zero divergence for every other rule.content/placeholder-text(#214) added the same parameter independently, emitting the separator on ENTERING a matching element only. That is enough between two blocks, which is all that rule needs, but not when a block is followed by inline content:<h3>Price *</h3><a>terms* apply</a>still reads back as*terms*, emphasis present in neither element. This branch keeps the symmetric version, which serves both rules, and merges the two test suites into one describe block. The consequence is that extracted text now carries a closing separator as well, which moved three exact-string expectations inpackages/rules/tests/placeholder-text.test.ts. Only the strings moved: each test still asserts what its name says, and every rule-outcome assertion in that suite is untouched and green.Rule counts after the rebase. Both branches bumped the published counts 279 to 280 with byte-identical edits, so git merged them as one change and raised no conflict, leaving every literal at 280 while the loader returned 281. Corrected across all five documentation surfaces; both per-category tables and all four score-group card sets sum to 281, with content at 20.
Precision
This rule accuses a page of a rendering bug, so it was measured against real sites rather than fixtures alone. 83 of 85 real pages clean, worst per-page rule time 10 ms. Each false positive found in the wild became a rule and a test:
td class="preformatted"preformattedjoins the highlighter class tokens<Article>,<Video>in the hero/pre<pre>and<meta name>in a breadcrumb/pre# the-pre-element, a URL fragment on its own line#is the number sign unless a capital followsProse full of identifiers stays clean:
CLOUDFLARE_API_TOKEN,some_file_name.ts,max_pages,__init__,2 * 3,width * height,array[i](arg),Johnson&Johnson;andif a<b then c=1>0are all covered by tests. Both emphasis forms require CommonMark flanking, and the underscore form additionally requires a space inside the run, which is what silences Python dunders.The residual is two w3schools tutorials that display HTML source in a bespoke
w3-codediv. That is reported honestly rather than tuned away: silencing every*-codeclass token would also silencepromo-codeanddiscount-code, which are prose. The docs page names this case and tells authors to use<pre>or<code>.Verification
Real-site sweep: 85 pages fetched, 83 clean. End to end through the CLI: a served page with a mis-rendered markdown field reports the finding and ignores the
<pre><code>block on the same page; the same page with its markdown correctly rendered is silent.The golden merge gate moved as a new rule id should.
findings98721 to 99221, which is one check on each of the 500 pages that have a document, andperRuleTally280 to 281. The pin asserts the rule's tally directly (pass: 500, warn: 0, fail: 0) rather than inferring "no false positives" from an unmoved health score, so the gate proves zero false positives across 500 synthetic pages.Two independent review passes ran over the diff (the
codexMCP was unavailable on this account, so both were fresh-eyes model reviews). Every finding is fixed and each has a regression test. The timing tests were rewritten after one pass showed the original fixtures carried a single trigger character each and could not detect backtracking at all: a deliberately bad pattern measured 0.1 ms on the old fixture and 5.2 seconds on a dense one. There are now 18 dense-trigger fixtures at a 400 ms budget.Follow-up for the gitlink bump
A rule change makes the private monorepo's generated catalogue stale. That bump needs
cd apps/api && bun run generate:rule-catalogplus thetotalRulesliteral and its header comment inapps/web/src/components/rules.tsx, orTest - APIgoes red on the rule-count and catalogue drift guards.Checklist
Signed-off-byline (git commit -s).