Repository navigation
Commit 51a1368
authored
fix(v4): let the includes(position) pattern match at or after the offset (#6024)
`String.prototype.includes(sub, position)` treats position as a start offset,
so it matches at that index or any later one. The pattern this check
advertised used `{N}`, which pins the substring to exactly index N, and
`z.toJSONSchema()` emitted it verbatim — a schema generated from
`z.string().includes("foo", { position: 2 })` rejected "xxxfoo" while the
validator accepted it. At `position: 0` the emitted pattern was equivalent to
startsWith.
The pattern reaches past JSON Schema output. It becomes the string's
`_zod.pattern`, which template literals compose into their own regex, and the
AOT compiler treats it as the entire check — so the compiled fast path
rejected a late match and fell back to the runtime on every one.
The string tests have asserted the "at or later" reading since before the
pattern existed: one parses "XXXincludesXX" through `position: 2`, where the
substring starts at index 3.1 parent a0bfdb3 commit 51a1368
2 files changed
Lines changed: 19 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
499 | | - | |
| 499 | + | |
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| |||
535 | 535 | | |
536 | 536 | | |
537 | 537 | | |
538 | | - | |
| 538 | + | |
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
| |||
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
555 | 568 | | |
556 | 569 | | |
557 | 570 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
974 | 974 | | |
975 | 975 | | |
976 | 976 | | |
977 | | - | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
978 | 981 | | |
979 | 982 | | |
980 | 983 | | |
| |||
0 commit comments