Skip to content

test(lint): fail when a RegExp is built from text that is not escaped - #8128

Merged
ukimsanov merged 1 commit into
mainfrom
test/lint-regexp-escape-guard
Nov 18, 2026
Merged

ukimsanov merged 1 commit into
mainfrom
test/lint-regexp-escape-guard

Conversation

@ukimsanov

Copy link
Copy Markdown
Collaborator

What

One new test, packages/lint/src/regexpInputsEscaped.test.ts. It reads every RegExp the lint package builds, with TypeScript's parser, and fails when a template input is not one of:

  • escapeRegExp(...)
  • a name starting with escaped
  • an ALL_CAPS constant

A plain string or a copied .source passes. Three inputs that cannot carry page text are listed with the reason: name in linearScans.ts (one of the fixed PROTECTED_NAMES words), receivers in rules/gsap.ts (each name already passed through escapeRegExp), and tagAlternation in utils.ts (a fixed alternation from mediaSrcTagRe's callers). No lint code changes.

Why

#8028 fixed a tag name that went into new RegExp unescaped, 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 with typescript (already a lint dev dependency), and checks the first argument of each new RegExp(...) and RegExp(...). On main it reads all 41 RegExp( calls in the package, the same count grep finds.

Test plan

  • fails without the fix: regexpInputsEscaped.test.ts "the linter builds no regular expression from unescaped text" fails with rules/media.ts:448 name when media.ts goes back to the code before fix(lint): match a timed wrapper's close tag literally #8028 (new RegExp(`</${name}>`, "gi")).
  • With the allow-list emptied, it names exactly the three listed inputs (four places) and nothing else.
  • packages/lint: 29 test files, 1337 tests pass. oxlint, oxfmt, tsc --noEmit, the comment ratchet, check-comment-citations and check-test-reachability pass.
  • Unit tests added/updated
  • Manual testing performed (test only)
  • Documentation updated (if applicable): not applicable
  • Comments follow CONTRIBUTING.md "Comments"

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 eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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

  1. 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.
  2. 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.

@ukimsanov
ukimsanov added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit dcdd340 Nov 18, 2026
67 checks passed
@ukimsanov
ukimsanov deleted the test/lint-regexp-escape-guard branch November 18, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants