Skip to content

Commit

Permalink
Fix multibyte handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gogainda committed Apr 9, 2021
1 parent 041c59e commit abfe817
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bug fixes:
Compatibility:

* Make interpolated strings frozen for compatibility with Ruby 2.7 (#2304, @kirs).
* Make rpartition compatible with Ruby 2.7 (#2320, @gogainda).

Performance:

Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/string/rpartition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"hello".rpartition("/no_match/").last.object_id.should_not eql("hello".object_id)
end

it "handles multibyte string correctly" do
"ユーザ@ドメイン".rpartition(/@/).should == ["ユーザ", "@", "ドメイン"]
end

it "accepts regexp" do
"hello!".rpartition(/l./).should == ["hel", "lo", "!"]
end
Expand Down
2 changes: 1 addition & 1 deletion src/main/ruby/truffleruby/core/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def partition(pattern=nil)

def rpartition(pattern)
if pattern.kind_of? Regexp
if m = Truffle::RegexpOperations.search_region(pattern, self, 0, size, false)
if m = Truffle::RegexpOperations.search_region(pattern, self, 0, bytesize, false)
Primitive.regexp_last_match_set(Primitive.caller_special_variables, m)
return [m.pre_match, m[0], m.post_match]
end
Expand Down
1 change: 0 additions & 1 deletion test/mri/excludes/TestString.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
exclude :test_lines, "needs investigation"
exclude :test_partition, "needs investigation"
exclude :test_respond_to, "needs investigation"
exclude :test_rpartition, "needs investigation"
exclude :test_rstrip, "needs investigation"
exclude :test_rstrip_bang, "needs investigation"
exclude :test_setter, "needs investigation"
Expand Down

0 comments on commit abfe817

Please sign in to comment.