Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/strscan/strscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,8 +1862,13 @@ strscan_integer_at(int argc, VALUE *argv, VALUE self)
return Qnil;

beg = adjust_register_position(p, p->regs.beg[i]);
if (beg > S_LEN(p))
return Qnil;
end = adjust_register_position(p, p->regs.end[i]);
end = minl(end, S_LEN(p));
len = end - beg;
if (len == 0)
return Qnil;
ptr = S_PBEG(p) + beg;
#ifdef HAVE_RB_INT_PARSE_CSTR
{
Expand Down
20 changes: 20 additions & 0 deletions test/strscan/test_stringscanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,26 @@ def test_integer_at_base_auto
assert_integer_at(s, 0, 0) # 0xaf
end

def test_integer_at_shrunk
omit("not supported on TruffleRuby") if RUBY_ENGINE == "truffleruby"

s = create_string_scanner(+"before 29 after")
s.skip_until(" ")
assert_equal("29", s.scan(/\d+/))
s.string.replace("before ")
assert_nil(s.integer_at(0))
end

def test_integer_at_shrunk_partial
omit("not supported on TruffleRuby") if RUBY_ENGINE == "truffleruby"

s = create_string_scanner(+"before 29 after")
s.skip_until(" ")
assert_equal("29", s.scan(/\d+/))
s.string.replace("before 2")
assert_integer_at(s, 2)
end

def test_pre_match
s = create_string_scanner('a b c d e')
s.scan(/\w/)
Expand Down
Loading