Skip to content

Commit

Permalink
[Normative] Fix off-by-1 error in PartitionPattern
Browse files Browse the repository at this point in the history
Right now after the loop finishes, the remainder is
`pattern.substring(nextIndex + 1, len)` (bc it's exclusive) but should
be `pattern.substring(nextIndex, len)` instead since `nextIndex` is
already set to `endIndex + 1` in the loop.

Take `AA{0}BB` as an example, after the loop finishes:
- beginIndex = -1
- endIndex = 4
- nextIndex = 5

so `pattern.substring(5, 7)` yields `BB` (correct) vs the old behavior
would just yield `B`
  • Loading branch information
longlho authored and Long Ho committed Jan 8, 2020
1 parent 38cf981 commit 6c7d38e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion spec/negotiation.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ <h1>PartitionPattern ( _pattern_ )</h1>
1. Set _nextIndex_ to _endIndex_ + 1.
1. Set _beginIndex_ to ! Call(%String.prototype.indexOf%, _pattern_, &laquo; *"{"*, _nextIndex_ &raquo;).
1. If _nextIndex_ is less than _length_, then
1. Let _literal_ be the substring of _pattern_ from position _nextIndex_, exclusive, to position _length_, exclusive.
1. Let _literal_ be the substring of _pattern_ from position _nextIndex_, inclusive, to position _length_, exclusive.
1. Add new part record { [[Type]]: *"literal"*, [[Value]]: _literal_ } as a new element of the list _result_.
1. Return _result_.
</emu-alg>
Expand Down

0 comments on commit 6c7d38e

Please sign in to comment.