webcheck: reject doubled unicode escapes in index.html #568
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix-escguard"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The static guard proposed on #552. Test-only — no behaviour change, so no CHANGELOG entry and no release.
What it catches
"·"is a middle dot."\\u00b7"is a backslash followed by the five charactersu00b7, and the browser renders exactly that. The two are nearly identical in a diff and identical in a code review at speed.This has bitten the same feature four times, three of which reached a release:
[._\\s-]Fall 1→ "FA"TestI18nKeysDefined\\u00b7Only the second had an automated net under it. The third was caught by a human reading the screen — which is not a control.
Why it keeps happening
It is structural, not careless.
index.htmlis edited by one-shot scripts that pass replacement text through a shell heredoc and a Python string on its way into JavaScript. Every layer has an opinion about backslashes and only the running browser reveals which one won. Writing the fix correctly is not enough; the fix has to survive the transport.The rule
No
\\uXXXXanywhere inindex.html. The one legitimate use — a string later handed tonew RegExp, where the regex engine performs the second decoding — is allowed with an explicit line marker:A marker rather than "outside a regex literal" on purpose: correctly finding regex literals in JavaScript means resolving the
/ambiguity, which is real parsing work and would itself be a source of bugs. A greppable, reviewable opt-out is the honest trade — and it makes the rare legitimate case visible rather than indistinguishable from the defect.doubledEscapesreports file line number and matched text for every occurrence, because a bare count is useless in a 12,000-line page.On the test data
The fixtures use Go raw strings, so backslashes are taken literally and the test file cannot fall to the very problem it exists to catch. Worth stating, given the subject.
The detector itself is emitted by a Python heredoc — the exact layering under scrutiny — so its regex is assembled from
chr(92)rather than typed, and no line in that generator contains a backslash Python could reinterpret.Verification
Red witnessed first:
undefined: doubledEscapesat three call sites, build failed. Then 13 detector cases (correct escape left alone, doubled form caught, real character ignored, multiple per line and per file, uppercase hex, a doubled backslash that is not an escape left alone, the marker working and scoped to its own line, empty input), a line-number assertion, and the real-file check overindex.html— which passes, so this lands as a clean baseline rather than a backlog. Full Go suite and all web tests green.