Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 77a01b4065a6
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: aae1efe3eba4
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Apr 15, 2016

  1. [Truffle] The string_byte_substring primitive should normalize inde…

    …x by byte length, not character length.
    nirvdrum committed Apr 15, 2016
    Copy the full SHA
    2f692d9 View commit details
  2. Copy the full SHA
    aae1efe View commit details
Showing with 5 additions and 4 deletions.
  1. +1 −0 spec/ruby/core/string/byteslice_spec.rb
  2. +4 −4 truffle/src/main/java/org/jruby/truffle/core/rubinius/StringPrimitiveNodes.java
1 change: 1 addition & 0 deletions spec/ruby/core/string/byteslice_spec.rb
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
"\u3042".byteslice(1).should == "\x81".force_encoding("UTF-8")
"\u3042".byteslice(1, 2).should == "\x81\x82".force_encoding("UTF-8")
"\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8")
"\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8")
end
end
end
Original file line number Diff line number Diff line change
@@ -342,14 +342,14 @@ public Object stringByteSubstring(DynamicObject string, int index, int length,
}

final Rope rope = rope(string);
final int stringLength = rope.characterLength();
final int normalizedIndex = StringOperations.normalizeIndex(stringLength, index);
final int stringByteLength = rope.byteLength();
final int normalizedIndex = StringOperations.normalizeIndex(stringByteLength, index);

if (indexOutOfBoundsProfile.profile(normalizedIndex < 0 || normalizedIndex > rope.byteLength())) {
if (indexOutOfBoundsProfile.profile(normalizedIndex < 0 || normalizedIndex > stringByteLength)) {
return nil();
}

if (lengthTooLongProfile.profile(normalizedIndex + length > rope.byteLength())) {
if (lengthTooLongProfile.profile(normalizedIndex + length > stringByteLength)) {
length = rope.byteLength() - normalizedIndex;
}