Fix regex validator crash on invalid patterns in jquery.validate.unobtrusive.js
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
## Issue
The `regex` custom validator in `jquery.validate.unobtrusive.js` (shipped with ASP.NET Core Identity UI) throws a `SyntaxError` when `new RegExp(params)` encounters an invalid regex pattern from `data-val-regex-pattern`. This crashes all client-side form validation on the page.
## Steps to Reproduce
A `[RegularExpression]` attribute with an invalid pattern (e.g., unbalanced brackets) generates a `data-val-regex-pattern` attribute. When jQuery Validate evaluates `new RegExp(params)`, it throws.
## Proposed Fix
Wrap the `new RegExp()` call in a try-catch so invalid patterns skip validation gracefully instead of crashing. Server-side validation at form submission remains the authoritative fallback.
Found via static analysis of the ASP.NET Core codebase.
Contributor guide
Assessment
This issue has not been assessed yet.