Many of Oniguruma functions need valid encoding strings

This commit is contained in:
Nobuyoshi Nakada 2024-11-26 11:05:16 +09:00 committed by Nobuyoshi Nakada
parent 02b70256b5
commit 6b4f8945d6
Notes: git 2024-11-26 02:46:54 +00:00
2 changed files with 6 additions and 1 deletions

View File

@ -3076,7 +3076,8 @@ rb_str_subpos(VALUE str, long beg, long *lenp)
}
if (beg < 0) {
if (len > -beg) len = -beg;
if (-beg * rb_enc_mbmaxlen(enc) < blen / 8) {
if ((ENC_CODERANGE(str) == ENC_CODERANGE_VALID) &&
(-beg * rb_enc_mbmaxlen(enc) < blen / 8)) {
beg = -beg;
while (beg-- > len && (e = rb_enc_prev_char(s, e, e, enc)) != 0);
p = e;

View File

@ -169,6 +169,10 @@ CODE
assert_equal(nil, S("\u{3042 3044 3046}")[RbConfig::LIMITS["LONG_MIN"], 1])
end
def test_AREF_invalid_encoding
assert_equal(S("\x80"), S("A"*39+"\x80")[-1, 1])
end
def test_ASET # '[]='
s = S("FooBar")
s[0] = S('A')