[ruby-core:109836] [Ruby master Bug#18670] MatchData#[start, length] pads nil values when negative start is given
From:
"nagachika (Tomoyuki Chikanaga)" <noreply@...>
Date:
2022-09-04 07:25:24 UTC
List:
ruby-core #109836
Issue #18670 has been updated by nagachika (Tomoyuki Chikanaga).
Backport changed from 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE
ruby_3_1 1cfc139f6d0cb80d6024b0c416976194929417cf merged revision(s) d8189ed23f02dd197453279aeee9be1785337d4f.
----------------------------------------
Bug #18670: MatchData#[start, length] pads nil values when negative start is given
https://bugs.ruby-lang.org/issues/18670#change-99073
* Author: bjfish (Brandon Fish)
* Status: Closed
* Priority: Normal
* ruby -v: 3.0.3
* Backport: 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE
----------------------------------------
Example
``` ruby
irb(main):001:0> /(.)(.)(\d+)(\d)/.match("THX1138.")[-1, 10]
=> ["8", nil, nil, nil, nil, nil, nil, nil, nil, nil]
```
I would expect this to be consistent with String or Array for example:
``` ruby
irb(main):002:0> "hello"[-1, 10]
=> "o"
irb(main):003:0> [1,2,3][-1,10]
=> [3]
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>