summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-11-26 11:05:16 +0900
committerNobuyoshi Nakada <[email protected]>2024-11-26 11:46:34 +0900
commit6b4f8945d600168bf530d21395da8293fbd5e8ba (patch)
tree00423c31613b2b7b3ce91ed7b745f67ebbd77944 /string.c
parent02b70256b5171d4b85ea7eeab836d3d7cfb3dbfc (diff)
Many of Oniguruma functions need valid encoding strings
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12169
Diffstat (limited to 'string.c')
-rw-r--r--string.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/string.c b/string.c
index c9db5d35c5..b970c5c6f5 100644
--- a/string.c
+++ b/string.c
@@ -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;