Repository navigation
test(lint): fail when a RegExp is built from text that is not escaped - #8128
Conversation
A tag name went into new RegExp unescaped, so a page could hang or crash the linter (#8028). This test reads every RegExp the lint package builds and fails when a template input is not escapeRegExp(...), an escaped* name or an ALL_CAPS constant. Three inputs that cannot carry page text are listed with the reason.
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit 9ce52f3. Small, test-only PR: I read the whole file myself.
Verdict: approved, good to ship.
Summary. One new test in the lint package walks every non-test source file with the TypeScript parser and fails if a regular expression is constructed from anything other than a literal, another expression's .source, or template parts that are passed through the escaping helper (or named as escaped, or an all-caps constant). Three existing call sites that are safe for a stated reason are listed by file and name. No lint code changes.
What I checked.
- A pattern passed as a plain variable is reported unless it is on the short allow list, so the default is strict.
- The allow list is keyed by file and exact expression text, so a new unescaped input in the same file is still reported.
Blockers
None.
Non-blockers
- The guard trusts names: an identifier that starts with "escaped", or is written in all capitals, passes without the test looking at how it was built. A reviewer still has to check that such a name is honest.
- It only sees the constructor called by its bare name. A pattern assembled as a string and handed to a helper that builds the expression elsewhere, or the constructor reached through another reference, is not seen. Fine for a regression guard on the pattern that caused the earlier bug.
CI: 47 checks pass at 9ce52f3, none failing or pending; 20 skipped.
How this was reviewed: I read the diff myself. Nothing was built or run.
What
One new test,
packages/lint/src/regexpInputsEscaped.test.ts. It reads everyRegExpthe lint package builds, with TypeScript's parser, and fails when a template input is not one of:escapeRegExp(...)escapedA plain string or a copied
.sourcepasses. Three inputs that cannot carry page text are listed with the reason:nameinlinearScans.ts(one of the fixedPROTECTED_NAMESwords),receiversinrules/gsap.ts(each name already passed throughescapeRegExp), andtagAlternationinutils.ts(a fixed alternation frommediaSrcTagRe's callers). No lint code changes.Why
#8028 fixed a tag name that went into
new RegExpunescaped, so a page could hang the linter or make it throw. That bug is a pattern, not one line. This test stops the next one at review time instead of in a user's terminal.Related work
Follows #8028. #7974 already runs Studio's and the producer's lint in a bounded child or worker; one-shot CLI commands keep linting in process, as #7974 decided.
How
The test walks
packages/lint/src(not tests), parses each file withtypescript(already a lint dev dependency), and checks the first argument of eachnew RegExp(...)andRegExp(...). On main it reads all 41RegExp(calls in the package, the same countgrepfinds.Test plan
regexpInputsEscaped.test.ts"the linter builds no regular expression from unescaped text" fails withrules/media.ts:448 namewhenmedia.tsgoes back to the code before fix(lint): match a timed wrapper's close tag literally #8028 (new RegExp(`</${name}>`, "gi")).packages/lint: 29 test files, 1337 tests pass. oxlint, oxfmt,tsc --noEmit, the comment ratchet,check-comment-citationsandcheck-test-reachabilitypass.