[ruby-core:96830] [Ruby master Bug#11014] String#partition doesn't return correct result on zero-width match
From:
mame@...
Date:
2020-01-14 02:49:30 UTC
List:
ruby-core #96830
Issue #11014 has been updated by mame (Yusuke Endoh). We'd like to focus on String#partition in this ticket. IMO, String#scan and #split are heavily used so they should not change just for consistency reason. Please create another ticket if you really need to discuss. And a patch suggestion is welcome. ---------------------------------------- Bug #11014: String#partition doesn't return correct result on zero-width match https://bugs.ruby-lang.org/issues/11014#change-83829 * Author: janko (Janko Marohnić) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: * ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- First, to see how `String#match` works on my example: ~~~ruby match = "foo".match(/^=*/) match.pre_match #=> "" match[0] #=> "" match.post_match #=> "foo" ~~~ Now, if I used `String#partition` instead of `match`, I'd expect to get `["", "", "foo"]` (pre_match, match, post_match). However ~~~ruby "foo".partition(/^=*/) #=> ["foo", "", ""] ~~~ `String#rpartition` returns the correct result (with the same regex). -- 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>