Skip to content

Commit 5eaee2f

Browse files
gibson042ljharb
authored andcommitted
Normative: Update GetSubstitution to match reality (#3157)
$nn patterns fall back to $n when there aren't at least nn captures Fixes #1426
1 parent a9ae96e commit 5eaee2f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spec.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34929,11 +34929,16 @@ <h1>
3492934929
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%.
3493034930
1. Else if _templateRemainder_ starts with *"$"* followed by 1 or more decimal digits, then
3493134931
1. If _templateRemainder_ starts with *"$"* followed by 2 or more decimal digits, let _digitCount_ be 2. Otherwise, let _digitCount_ be 1.
34932-
1. Let _ref_ be the substring of _templateRemainder_ from 0 to 1 + _digitCount_.
3493334932
1. Let _digits_ be the substring of _templateRemainder_ from 1 to 1 + _digitCount_.
3493434933
1. Let _index_ be ℝ(StringToNumber(_digits_)).
3493534934
1. Assert: 0 ≤ _index_ ≤ 99.
3493634935
1. Let _captureLen_ be the number of elements in _captures_.
34936+
1. If _index_ > _captureLen_ and _digitCount_ = 2, then
34937+
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.
34938+
1. Set _digitCount_ to 1.
34939+
1. Set _digits_ to the substring of _digits_ from 0 to 1.
34940+
1. Set _index_ to ℝ(StringToNumber(_digits_)).
34941+
1. Let _ref_ be the substring of _templateRemainder_ from 0 to 1 + _digitCount_.
3493734942
1. If 1 ≤ _index_ ≤ _captureLen_, then
3493834943
1. Let _capture_ be _captures_[_index_ - 1].
3493934944
1. If _capture_ is *undefined*, then

0 commit comments

Comments
 (0)