Skip to content

Commit c17b015

Browse files
authored
Don't add begin to length for new string slice (#87)
Fixes #86
1 parent 842845a commit c17b015

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ private RubyString newString(Ruby runtime, int start, int length) {
874874
ByteList byteList = str.getByteList();
875875
int begin = byteList.begin();
876876

877-
ByteList newByteList = new ByteList(byteList.unsafeBytes(), begin + start, begin + length, byteList.getEncoding(), true);
877+
ByteList newByteList = new ByteList(byteList.unsafeBytes(), begin + start, length, byteList.getEncoding(), true);
878878

879879
return RubyString.newString(runtime, newByteList);
880880
}

test/strscan/test_stringscanner.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,4 +841,12 @@ def test_skip_with_begenning_of_line_anchor_not_match
841841
assert_equal 1, s.skip(/a/)
842842
assert_nil s.skip(/^b/)
843843
end
844+
845+
# ruby/strscan#86
846+
def test_scan_shared_string
847+
s = "hellohello"[5..-1]
848+
ss = StringScanner.new(s).scan(/hello/)
849+
850+
assert_equal "hello", ss
851+
end
844852
end

0 commit comments

Comments
 (0)