fix(runtime): spec-compliant String.prototype.split with a RegExp separator (test262 tail) - #5027
Merged
Merged
Conversation
…arator
built-ins/String + built-ins/RegExp test262: +8, zero regressions.
Perry delegated regex split to the Rust `regex` crate's `Regex::split`, which
diverges from JS `RegExp.prototype[Symbol.split]` (21.2.5.11) in two ways:
* zero-width matches — `regex::split` emits leading/trailing/consecutive empty
strings that the spec's `e == p` skip suppresses, so
`"abc".split(/(?:)/)` returned `["","a","b","c",""]` instead of
`["a","b","c"]`; and
* captured groups were never spliced into the result.
Replaced the standard-engine branch with the spec algorithm: a sticky match at
each position, the empty-match-at-segment-start skip, and capture-group
splicing (unmatched groups → `undefined`). The helpers live in
`string/split.rs` (keeps `regex.rs` under the 2000-line cap). The
fancy-regex (lookbehind) fallback is unchanged.
Fixes the String.prototype.split/call-split-new-reg-exp + new-reg-exp-and-N +
separator-regexp cluster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
built-ins/String+built-ins/RegExptest262: +8, zero regressions (verified by diffing the per-test failure set; String+RegExp fails 97 → 89).Root cause
Perry delegated
String.prototype.split(regexp, limit)to the Rustregexcrate'sRegex::split, which diverges from JSRegExp.prototype[Symbol.split](21.2.5.11):regex::splitemits the leading/trailing/consecutive empty strings that the spec'se == pskip suppresses."one-1 two".split(new RegExp)(empty pattern) returned["","o",…,"o",""](length 11) instead of the spec's["o",…,"o"](length 9, one element per char); and"a1b".split(/(\d)/)dropped the"1").Fix
Replaced the standard-engine branch of
js_string_split_regex_nwith the spec algorithm: a sticky match at each position, the empty-match-at-segment-start (e == p) skip, and capture-group splicing where an unmatched group becomesundefined.limitis honoured per-element. The fancy-regex (lookbehind) fallback is unchanged. Helpers (spec_regex_split,next_char_boundary) live instring/split.rssoregex.rsstays under the 2000-line cap.Files
regex.rs— standard split branch + undefined-aware array buildstring/split.rs—spec_regex_split+next_char_boundarystring/mod.rs— re-exportValidation
test262_subset.py --dir built-ins/String built-ins/RegExpvs tc39/test262 @4249661, Node v26.3.0: 8 newly-passing (split/call-split-new-reg-exp, the new-reg-exp-and-N family, separator-regexp), 0 newly-broken.