[ruby/strscan] scan_integer(base: 16) ignore x suffix if not

followed by hexadecimal
(https://github.com/ruby/strscan/pull/141)

Fix: https://github.com/ruby/strscan/issues/140

`0x<EOF>`, `0xZZZ` should be parsed as `0` instead of not matching at
all.

c4e4795ed2
This commit is contained in:
Jean Boussier 2025-02-20 10:25:03 +01:00 committed by Hiroshi SHIBATA
parent 0f8a6e1f59
commit bf6c106d54
2 changed files with 15 additions and 10 deletions

View file

@ -1379,7 +1379,7 @@ strscan_scan_base16_integer(VALUE self)
len++;
}
if ((remaining_len >= (len + 2)) && ptr[len] == '0' && ptr[len + 1] == 'x') {
if ((remaining_len >= (len + 3)) && ptr[len] == '0' && ptr[len + 1] == 'x' && rb_isxdigit(ptr[len + 2])) {
len += 2;
}