From 7d144781a93df66379922717da711a09d1cf78ff Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 28 May 2024 16:59:51 +0900 Subject: [PATCH] [Bug #20512] Set coderange in `Range#each` of strings --- string.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/string.c b/string.c index 83539ec8f4..ad1e76cdc9 100644 --- a/string.c +++ b/string.c @@ -5156,7 +5156,9 @@ rb_str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALU if (c > e || (excl && c == e)) return beg; for (;;) { - if ((*each)(rb_enc_str_new(&c, 1, enc), arg)) break; + VALUE str = rb_enc_str_new(&c, 1, enc); + ENC_CODERANGE_SET(str, RUBY_ENC_CODERANGE_7BIT); + if ((*each)(str, arg)) break; if (!excl && c == e) break; c++; if (excl && c == e) break;