Bug #1510

[patch] String#partition can return wrong result or crash

Added by marcandre (Marc-Andre Lafortune) almost 3 years ago. Updated about 1 year ago.

[ruby-core:23540]
Status:Closed Start date:05/25/2009
Priority:Normal Due date:
Assignee:- % Done:

100%

Category:core
Target version:1.9.2
ruby -v:ruby 1.9.2dev (2009-05-24 trunk 23557) [i386-darwin9.7.0]

Description

The attached patch fixes a problem that occurs when the argument of String#partition needs to be converted using :to_str.

E.g:

class C
  def to_str
    "foo"
  end
end
p "foo-bar".partition(C.new)

Before patch:
["", #<C:0x2c62a8>, "foo-bar"]

After patch:
["", "foo", "-bar"]

RubySpecs has been updated. Without the version guard, it crashes Ruby.

partition.patch (332 Bytes) marcandre (Marc-Andre Lafortune), 05/25/2009 07:36 am

Associated revisions

Revision 23562
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

* string.c (rb_str_partition): should use the converted result. a patch from Marc-Andre Lafortune at [ruby-core:23540].

History

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
Applied in changeset r23562.

Updated by marcandre (Marc-Andre Lafortune) almost 3 years ago

Thanks, that was really quick!
I just noticed that rpartition has the same problem...

Also available in: Atom PDF