Skip to content

JavaScript: Reduce FPs in missing-regexp-anchor for intentional partial matching#22

Open
mrigankpawagi wants to merge 1 commit into
mainfrom
improve-js-missing-regexp-anchor-test
Open

JavaScript: Reduce FPs in missing-regexp-anchor for intentional partial matching#22
mrigankpawagi wants to merge 1 commit into
mainfrom
improve-js-missing-regexp-anchor-test

Conversation

@mrigankpawagi

Copy link
Copy Markdown
Owner

Fix

Excludes unanchored regex patterns from the js/regex/missing-regexp-anchor query when they consist of simple word alternatives (no dots) used with .test() for role/type checking.

Problem

The query flags patterns like /admin|moderator|user/.test(role) as missing anchors. However, these are intentional partial matches for role/type checking - not hostname validation. The alternatives contain no dots (unlike hostname patterns), indicating they are not URL-related.

Validation

The fix is conservative: it only excludes patterns where ALL alternatives are dot-free simple words AND the pattern is used with .test(). Hostname-like patterns (containing dots) remain flagged.

When a regex with misleading anchor precedence is used with .test()
and the unanchored alternatives are simple words (no dots/TLD patterns),
it is likely an intentional partial match for role/type checking rather
than a hostname validation bypass.
@github-actions github-actions Bot added the JS label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants