diff options
| author | Kasumi Hanazuki <kasumi@rollingapple.net> | 2020-08-13 03:37:32 +0000 |
|---|---|---|
| committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-08-13 20:50:50 +0900 |
| commit | 5d71eed1a7f0a70db013de59cd7e95bdca0d5c0e (patch) | |
| tree | 99bc9c8b9bf059d8db50721841cb43bba8ca12d1 /include | |
| parent | 69b5241c360aa180550538dba1c7bf0a6cc8cc22 (diff) | |
rb_str_{partition,rpartition}_m: Handle /\K/ in pattern
When the pattern given to String#partition and String#rpartition
contain a /\K/ (lookbehind) operator, the methods return strings
sliced at incorrect positions.
```
# without patch
"abcdbce".partition(/b\Kc/) # => ["a", "c", "cdbce"]
"abcdbce".rpartition(/b\Kc/) # => ["abcd", "c", "ce"]
```
This patch fixes the problem by using BEG(0) instead of the return
value of rb_reg_search.
```
# with patch
"abcdbce".partition(/b\Kc/) # => ["ab", "c", "dbce"]
"abcdbce".rpartition(/b\Kc/) # => ["abcdb", "c", "e"]
```
As a side-effect this patch makes String#partition 2x faster when the
pattern is a costly Regexp by performing Regexp search only once,
which was unexpectedly done twice in the original implementation.
Fixes [Bug #17119]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3413
Diffstat (limited to 'include')
0 files changed, 0 insertions, 0 deletions
