From: "saddestmartian (sad mart) via ruby-core" Date: 2026-12-04T05:44:22+00:00 Subject: [ruby-core:127846] [Ruby Bug#22718] String#each_line with a broken separator returns lines with a stale valid coderange Issue #22718 has been reported by saddestmartian (sad mart). ---------------------------------------- Bug #22718: String#each_line with a broken separator returns lines with a stale valid coderange https://bugs.ruby-lang.org/issues/22718 * Author: saddestmartian (sad mart) * Status: Open * ruby -v: ruby 4.1.0dev (2026-12-03T23:00:19Z master bcd243e8e8) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- `String#each_line` and `String#lines` with a broken separator return lines that report `valid_encoding? == true` although they are not valid: ```ruby s = "������"; s.valid_encoding? s.lines("\xE3") #=> ["\xE3", "\x81\x82\xE3", "\x81\x84"] s.lines("\xE3").map(&:valid_encoding?) #=> [true, true, true], expected [false, false, false] ``` The end of a separator match is not a character boundary when the separator is broken, and `rb_str_subseq` copies the receiver's coderange (callers are expected to cut on boundaries, as in Bug #22700). The pull request below clears the coderange of the lines in that case and leaves the lines themselves unchanged. Whether a broken separator should match at all (`chomp`/`index` treat it as no match, `split` raises) is left open. It reproduces on master and 4.0.10. https://github.com/ruby/ruby/pull/20475 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/