Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ark/regex/__tests__/regex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ contextualize(() => {
attest<Regex<"ac" | `ab${string}c`, {}>>(S)
})

// https://github.com/arktypeio/arktype/issues/1625
it("* over a digit class allows the empty string", () => {
const S = regex("^(\\d*)$")
attest<Regex<"" | `${number}`, { captures: ["" | `${number}`] }>>(S)
})

it("? over a digit class allows the empty string", () => {
const S = regex("^(\\d?)$")
attest<Regex<"" | `${number}`, { captures: ["" | `${number}`] }>>(S)
})

it("unmatched ?", () => {
// @ts-expect-error
attest(() => regex("?")).type.errors(writeUnmatchedQuantifierError("?"))
Expand Down
8 changes: 6 additions & 2 deletions ark/regex/quantify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ type tryFastPath<
max extends number | null
> =
max extends 0 ? ""
: // repeating string or `${number}` any number of times will not change the type
: // repeating string or `${number}` any number of times will not change the
// type, but zero repetitions produce "", which `${number}` does not include
string extends pattern ? string
: `${number}` extends pattern ? `${number}`
: `${number}` extends pattern ?
min extends 0 ?
"" | `${number}`
: `${number}`
: min extends 0 ?
max extends 1 ? "" | pattern
: max extends number ? loopFromZero<pattern, max, "", []>
Expand Down
Loading