Skip to content

feat: allow RegExp validation patterns []#1622

Merged
Jared Jolton (jjolton-contentful) merged 1 commit into
mainfrom
feat/allow-regexp-validation-pattern
May 13, 2026
Merged

feat: allow RegExp validation patterns []#1622
Jared Jolton (jjolton-contentful) merged 1 commit into
mainfrom
feat/allow-regexp-validation-pattern

Conversation

@jjolton-contentful

@jjolton-contentful Jared Jolton (jjolton-contentful) commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Allow regexp.pattern and prohibitRegexp.pattern validations to accept JavaScript RegExp values.
  • Serialize RegExp patterns to CMA-safe { pattern, flags } payloads before content type requests are created.
  • Document and test flag precedence: explicit flags values override flags embedded in the RegExp.
  • Update public TypeScript declarations and add regression coverage for validation + payload generation.

Description

This keeps the existing string-based validation shape intact while allowing migration scripts to pass a RegExp instance as the pattern value. The generated payload stores RegExp.source as pattern, includes RegExp.flags when no explicit flags value is provided, and lets explicit flags values win when both are present.

Generated with Codex

Motivation and Context

Fixes #1178.

The previous string-only API requires awkward double escaping in migration scripts. Accepting RegExp values lets users write the same expression they would normally use in JavaScript while preserving the CMA payload contract.

PR Checklist

  • I have read the CONTRIBUTING.md file
  • All commits follow conventional commits
  • Documentation is updated (if necessary)
  • PR doesn't contain any sensitive information
  • There are no breaking changes

Test plan

  • npm run build
  • npm run test:unit
  • npm run lint
  • npm run test:typescript-declaration

@jjolton-contentful Jared Jolton (jjolton-contentful) force-pushed the feat/allow-regexp-validation-pattern branch from 57b0c74 to e32f015 Compare May 12, 2026 21:55
@jjolton-contentful Jared Jolton (jjolton-contentful) changed the title feat: allow RegExp validation patterns feat: allow RegExp validation patterns [] May 12, 2026
@jjolton-contentful Jared Jolton (jjolton-contentful) marked this pull request as ready for review May 12, 2026 21:59
@jjolton-contentful Jared Jolton (jjolton-contentful) force-pushed the feat/allow-regexp-validation-pattern branch from e32f015 to 2416d4f Compare May 12, 2026 22:04

@tylerpina Tyler Pina (tylerpina) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀

@jjolton-contentful Jared Jolton (jjolton-contentful) merged commit e88797d into main May 13, 2026
19 checks passed
@jjolton-contentful Jared Jolton (jjolton-contentful) deleted the feat/allow-regexp-validation-pattern branch May 13, 2026 15:52
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.

Validation with Regex doesn't allow type regexp for a pattern

2 participants