Skip to content

Commit

Permalink
Normative: Update GetSubstitution to match reality
Browse files Browse the repository at this point in the history
$nn patterns fall back to $n when there aren't at least nn captures

Fixes tc39gh-1426
  • Loading branch information
gibson042 committed Aug 29, 2023
1 parent 68881b6 commit da34cec
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -34770,11 +34770,16 @@ <h1>
1. NOTE: _tailPos_ can exceed _stringLength_ only if this abstract operation was invoked by a call to the intrinsic @@replace method of %RegExp.prototype% on an object whose *"exec"* property is not the intrinsic %RegExp.prototype.exec%.
1. Else if _templateRemainder_ starts with *"$"* followed by 1 or more decimal digits, then
1. If _templateRemainder_ starts with *"$"* followed by 2 or more decimal digits, let _digitCount_ be 2. Otherwise, let _digitCount_ be 1.
1. Let _ref_ be the substring of _templateRemainder_ from 0 to 1 + _digitCount_.
1. Let _digits_ be the substring of _templateRemainder_ from 1 to 1 + _digitCount_.
1. Let _index_ be ℝ(StringToNumber(_digits_)).
1. Assert: 0 ≤ _index_ ≤ 99.
1. Let _captureLen_ be the number of elements in _captures_.
1. If _index_ > _captureLen_ and _digitCount_ > 1, then
1. NOTE: When a two-digit replacement pattern specifies an index exceeding the count of capturing groups, it is treated as a one-digit replacement pattern followed by a literal digit.
1. Set _digitCount_ to 1.
1. Set _digits_ to the substring of _digits_ from 0 to 1.
1. Set _index_ to ℝ(StringToNumber(_digits_)).
1. Let _ref_ be the substring of _templateRemainder_ from 0 to 1 + _digitCount_.
1. If 1 ≤ _index_ ≤ _captureLen_, then
1. Let _capture_ be _captures_[_index_ - 1].
1. If _capture_ is *undefined*, then
Expand Down

0 comments on commit da34cec

Please sign in to comment.