Bug #8138

rpartition(regexp) for multibyte string

Added by Nobuhiro IMAI about 1 year ago. Updated about 1 year ago.

[ruby-dev:47183]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:-
ruby -v:ruby 2.1.0dev (2013-03-21 trunk 39858) [x86_64-linux] Backport:

Description

=begin
以下のように、String#rpartition に正規表現を渡したとき、マルチバイト文字列だと挙動がおかしいようです。

# encoding: UTF-8
"user@domain".partition("@") # => ["user", "@", "domain"]
"user@domain".partition(/@/) # => ["user", "@", "domain"]
"user@domain".rpartition("@") # => ["user", "@", "domain"]
"user@domain".rpartition(/@/) # => ["user", "@", "domain"]
"ユーザ@ドメイン".partition("@") # => ["ユーザ", "@", "ドメイン"]
"ユーザ@ドメイン".partition(/@/) # => ["ユーザ", "@", "ドメイン"]
"ユーザ@ドメイン".rpartition("@") # => ["ユーザ", "@", "ドメイン"]
"ユーザ@ドメイン".rpartition(/@/) # => ["ユーザ@ドメイン", "@", nil]
=end

Associated revisions

Revision 39903
Added by Akinori MUSHA about 1 year ago

Fix String#rpartition(/re/) against a multibyte string.

  • string.c (rbstrrpartition): Fix String#rpartition(/re/) against a multibyte string. [Bug #8138]

Revision 39906
Added by Yui NARUSE about 1 year ago

  • string.c (rbstrrpartition): revert r39903, and convert byte offset to char offset; the return value of rbregsearch is byte offset, but other than it of rbstrrpartition expects char offset. [Bug #8138]

History

#1 Updated by Akinori MUSHA about 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39903.
Nobuhiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Fix String#rpartition(/re/) against a multibyte string.

  • string.c (rbstrrpartition): Fix String#rpartition(/re/) against a multibyte string. [Bug #8138]

Also available in: Atom PDF