Skip to content

Commit 3c3edd5

Browse files
committed
[Truffle] Fixed String indexing by offset and length.
ByteList expects the end position and calculates the length itself. Passing the length ourselves results in a negative index exception.
1 parent 7ac8d1f commit 3c3edd5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public RubyString getIndex(RubyString string, int start, int length) {
242242
// TODO(CS): why does subSequence return CharSequence?
243243
final int begin = string.normaliseIndex(start);
244244
final int exclusiveEnd = string.normaliseIndex(begin + length);
245-
return new RubyString(getContext().getCoreLibrary().getStringClass(), (ByteList) string.getBytes().subSequence(begin, exclusiveEnd - begin));
245+
246+
return new RubyString(getContext().getCoreLibrary().getStringClass(), (ByteList) string.getBytes().subSequence(begin, exclusiveEnd));
246247
}
247248

248249
}

0 commit comments

Comments
 (0)