Skip to content

Commit 9690e39

Browse files
authored
jruby: Pass end index to byteListToInum (#150)
These parse methods take begin and end indices, not begin and length. A test is included. Fixes jruby/jruby#8823
1 parent ad2d71f commit 9690e39

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-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
@@ -651,7 +651,7 @@ private RubyInteger strscanParseInteger(Ruby runtime, ByteList bytes, int ptr, i
651651
setMatched();
652652
adjustRegisters();
653653

654-
return ConvertBytes.byteListToInum(runtime, bytes, ptr, len, base, true);
654+
return ConvertBytes.byteListToInum(runtime, bytes, ptr, ptr + len, base, true);
655655
}
656656

657657
private void strscanMustAsciiCompat(Ruby runtime) {

test/strscan/test_stringscanner.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,12 @@ def test_scan_integer
10061006
assert_equal(huge_integer.to_i, s.scan_integer)
10071007
assert_equal(2_000, s.pos)
10081008
assert_predicate(s, :matched?)
1009+
1010+
s = create_string_scanner('abc1')
1011+
s.pos = 3
1012+
assert_equal(1, s.scan_integer)
1013+
assert_equal(4, s.pos)
1014+
assert_predicate(s, :matched?)
10091015
end
10101016

10111017
def test_scan_integer_unmatch

0 commit comments

Comments
 (0)