Actions
Bug #13925
closedstring.split(pattern, 1) should return [self.dup], but it returns [self]
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
Backport:
Description
msg = 'abababababa'
msg.split('b', 4).map(&:upcase!) # won't overwrite msg
puts msg # abababababa (expected)
msg.split('b', 1).map(&:upcase!) # this overwrites msg
puts msg # ABABABABABA (abababababa is expected)
I wrote a patch for this.
Files
Updated by hanachin (Seiei Miyagi) over 7 years ago
There are same problem in partition and rpartition
I expect the s is "abc", but it is modified.
s = "abc"; s.partition("d").map(&:upcase!); s
# => "ABC"
I expect the s is "abc", but it is modified.
s = "abc"; s.rpartition("d").map(&:upcase!); s
# => "ABC"
If string is splitted, partition/rpartition returns the copy of a part of string.
s = "abc"; s.partition("b").map(&:upcase!); s
# => "abc"
s = "abc"; s.rpartition("b").map(&:upcase!); s
# => "abc"
Updated by hanachin (Seiei Miyagi) about 7 years ago
I added some tests and send a Pull Request to ruby/ruby
https://github.com/ruby/ruby/pull/1705
Updated by nobu (Nobuyoshi Nakada) about 7 years ago
- Status changed from Open to Closed
- Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
Updated by nagachika (Tomoyuki Chikanaga) almost 7 years ago
- Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE
ruby_2_4 r62667 merged revision(s) 60000,60001,60002.
Updated by usa (Usaku NAKAMURA) almost 7 years ago
- Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: REQUIRED, 2.3: DONE, 2.4: DONE
ruby_2_3 r62818 merged revision(s) 60000,60001,60002.
Actions
Like0
Like0Like0Like0Like0Like0