Project

General

Profile

Bug #13925

string.split(pattern, 1) should return [self.dup], but it returns [self]

Added by tompng (tomoya ishida) about 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
[ruby-core:82899]

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

split_limit_1.patch (352 Bytes) split_limit_1.patch tompng (tomoya ishida), 09/20/2017 04:31 PM
partition_rpartition.patch (842 Bytes) partition_rpartition.patch hanachin (Seiei Miyagi), 09/20/2017 11:44 PM

Associated revisions

Revision 60000
Added by nobu (Nobuyoshi Nakada) about 2 years ago

dup String#partition return value

  • string.c (rb_str_partition): return duplicated receiver, when no splits. [ruby-core:82911] [Bug#13925]

Author: Seiei Miyagi hanachin@gmail.com

Revision 60001
Added by nobu (Nobuyoshi Nakada) about 2 years ago

dup String#rpartition return value

  • string.c (rb_str_rpartition): return duplicated receiver, when no splits. [ruby-core:82911] [Bug#13925]

Author: Seiei Miyagi hanachin@gmail.com

Revision 60002
Added by nobu (Nobuyoshi Nakada) about 2 years ago

dup String#split return value

  • string.c (rb_str_split): return duplicated receiver, when no splits. patched by tompng (tomoya ishida) in [ruby-core:82911], and the test case by Seiei Miyagi hanachin@gmail.com. [Bug#13925] [Fix GH-1705]

Revision 6d742295
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 60000,60001,60002: [Backport #13925]

    dup String#partition return value

    * string.c (rb_str_partition): return duplicated receiver, when no
      splits.  [ruby-core:82911] [Bug#13925]

    Author:    Seiei Miyagi <hanachin@gmail.com>

    dup String#rpartition return value

    * string.c (rb_str_rpartition): return duplicated receiver, when
      no splits.  [ruby-core:82911] [Bug#13925]

    Author:    Seiei Miyagi <hanachin@gmail.com>

    dup String#split return value

    * string.c (rb_str_split): return duplicated receiver, when no
      splits.  patched by tompng (tomoya ishida) in [ruby-core:82911],
      and the test case by Seiei Miyagi <hanachin@gmail.com>.
      [Bug#13925] [Fix GH-1705]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62667
Added by nagachika (Tomoyuki Chikanaga) over 1 year ago

merge revision(s) 60000,60001,60002: [Backport #13925]

dup String#partition return value

* string.c (rb_str_partition): return duplicated receiver, when no
  splits.  [ruby-core:82911] [Bug#13925]

Author:    Seiei Miyagi <hanachin@gmail.com>

dup String#rpartition return value

* string.c (rb_str_rpartition): return duplicated receiver, when
  no splits.  [ruby-core:82911] [Bug#13925]

Author:    Seiei Miyagi <hanachin@gmail.com>

dup String#split return value

* string.c (rb_str_split): return duplicated receiver, when no
  splits.  patched by tompng (tomoya ishida) in [ruby-core:82911],
  and the test case by Seiei Miyagi <hanachin@gmail.com>.
  [Bug#13925] [Fix GH-1705]

Revision 1816ba09
Added by usa (Usaku NAKAMURA) over 1 year ago

merge revision(s) 60000,60001,60002: [Backport #13925]

    dup String#partition return value

    * string.c (rb_str_partition): return duplicated receiver, when no
      splits.  [ruby-core:82911] [Bug#13925]

    Author:    Seiei Miyagi <hanachin@gmail.com>

    dup String#rpartition return value

    * string.c (rb_str_rpartition): return duplicated receiver, when
      no splits.  [ruby-core:82911] [Bug#13925]

    Author:    Seiei Miyagi <hanachin@gmail.com>

    dup String#split return value

    * string.c (rb_str_split): return duplicated receiver, when no
      splits.  patched by tompng (tomoya ishida) in [ruby-core:82911],
      and the test case by Seiei Miyagi <hanachin@gmail.com>.
      [Bug#13925] [Fix GH-1705]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@62818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62818
Added by usa (Usaku NAKAMURA) over 1 year ago

merge revision(s) 60000,60001,60002: [Backport #13925]

dup String#partition return value

* string.c (rb_str_partition): return duplicated receiver, when no
  splits.  [ruby-core:82911] [Bug#13925]

Author:    Seiei Miyagi <hanachin@gmail.com>

dup String#rpartition return value

* string.c (rb_str_rpartition): return duplicated receiver, when
  no splits.  [ruby-core:82911] [Bug#13925]

Author:    Seiei Miyagi <hanachin@gmail.com>

dup String#split return value

* string.c (rb_str_split): return duplicated receiver, when no
  splits.  patched by tompng (tomoya ishida) in [ruby-core:82911],
  and the test case by Seiei Miyagi <hanachin@gmail.com>.
  [Bug#13925] [Fix GH-1705]

History

Updated by hanachin (Seiei Miyagi) about 2 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 2 years ago

I added some tests and send a Pull Request to ruby/ruby
https://github.com/ruby/ruby/pull/1705

#3

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
  • Status changed from Open to Closed

Updated by nagachika (Tomoyuki Chikanaga) over 1 year 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) over 1 year 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.

Also available in: Atom PDF