From: "saddestmartian (sad mart) via ruby-core" Date: 2026-12-04T05:31:28+00:00 Subject: [ruby-core:127843] [Ruby Bug#22715] String#each_line drops text before a separator match in the middle of a character Issue #22715 has been reported by saddestmartian (sad mart). ---------------------------------------- Bug #22715: String#each_line drops text before a separator match in the middle of a character https://bugs.ruby-lang.org/issues/22715 * 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 separator drop the text before a byte match of the separator that falls inside a multibyte character: ```ruby s = "a\x83\x5Cb\\c".force_encoding("Shift_JIS") # "\x83\x5C" is one character s.lines("\\") #=> ["b\\", "c"] expected ["a\x{835C}b\\", "c"] t = "a\x83\x5C".force_encoding("Shift_JIS") t.lines("\\") #=> [] expected ["a\x{835C}"] ``` In `rb_str_enumerate_lines`, skipping a match in the middle of a character moves the start of the current line as well as the search position, so the text before it is never yielded. The same class was fixed for `String#split` in fef67df224 (GitHub #19706). It affects encodings whose characters can contain the separator bytes after the first byte (Shift_JIS, Windows-31J, GBK, GB18030, Big5, CP949), and multibyte separators in EUC-JP. It reproduces on 2.1 through 3.4.13, 4.0.10 and master. A patch with tests: https://github.com/ruby/ruby/pull/20472 -- 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/