Skip to content

fix(fast-check): keep regex flags when generating matching strings - #1721

Open
RaphaelFakhri wants to merge 1 commit into
arktypeio:mainfrom
RaphaelFakhri:fix/fast-check-regex-flags
Open

RaphaelFakhri wants to merge 1 commit into
arktypeio:mainfrom
RaphaelFakhri:fix/fast-check-regex-flags

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

buildStringArbitrary rebuilt each pattern with new RegExp(rule), which drops the flags. For a pattern with the u flag, such as /^\u{1F600}[a-z]$/u, the arbitrary generated strings like "u{1F600}a" that fail the type. Ranges that need u threw SyntaxError: Range out of order.

This change passes the pattern's flags to fc.stringMatching, except i. fast-check rejects i, and leaving it out only narrows what gets generated, so every generated string still matches. Flags that fast-check doesn't support (y, v) now make fast-check throw instead of letting the arbitrary generate invalid strings.

The new regex with flags test fails on main with the counterexample "u{1F600}a" and passes with this change.

Fixes #1720

@github-project-automation github-project-automation Bot moved this to To do in arktypeio Nov 2, 2026
ssalbdivad added a commit that referenced this pull request Nov 9, 2026
buildStringArbitrary rebuilt each pattern with `new RegExp(rule)`, dropping
its flags. Without u, `\u{1F600}` reads as the text "u{1F600}", so every
string generated for /^\u{1F600}[a-z]$/u failed the type, and a range that
needs u (/^[😀-😂]$/u) threw "Range out of order".

The pattern's flags now reach fc.stringMatching, minus i: fast-check rejects
i, and a string matching without i also matches with it, so dropping it only
narrows what is generated. y and v are passed through so fast-check throws
instead of generating strings the type rejects (dropping y is unsound: /a/y
generated "ba"-shaped strings, 272/300 failing in a probe). \p{...} under u
now throws fast-check's "UnicodeProperty not implemented" instead of
generating the literal "p{Lu}".

Ports #1721 (RaphaelFakhri). Closes #1720.
ssalbdivad added a commit that referenced this pull request Nov 9, 2026
…uthors

Each fix below landed on featherduster from a port or an independent fix,
but each started from a reasonable community PR against 2.x, and the
CHANGELOG thanks every contributor whose work this release supersedes:

- #1721 (@RaphaelFakhri): fast-check keeps a regex's flags (#1720)
- #1722 (@louisss1016): Temporal values survive a morph / deepClone (#1719)
- #1725 (@RClaudiuM): an undefined discriminant case checks its key (#1724)
- #1715 (@SynthLuvr): ~standard.jsonSchema.input drops undefined (#1462);
  only its input half was taken, output keeps routing to fallback.unit

#1718 is not credited: 3.0 answers #1469 with jsonSchema meta rather than
its bare pattern key. #1705 and #1695 were already thanked.

Also notes that a cyclic index signature with no way out now generates
shrinking dictionaries instead of overflowing the stack (6f4dd5d).
@ssalbdivad ssalbdivad mentioned this pull request Nov 9, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

@ark/fast-check generates strings that fail the type when the regex has the u flag

1 participant