From: "jhawthorn (John Hawthorn) via ruby-core" Date: 2026-11-25T03:21:10+00:00 Subject: [ruby-core:127706] [Ruby Bug#22636] String#rindex misses a match when its first byte repeats within the first character Issue #22636 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #22636: String#rindex misses a match when its first byte repeats within the first character https://bugs.ruby-lang.org/issues/22636 * Author: jhawthorn (John Hawthorn) * Status: Open * ruby -v: ruby 4.1.0dev (2026-11-25T00:33:09Z HEAD 6698249e41) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: REQUIRED, 4.0: REQUIRED ---------------------------------------- `String#rindex` misses a match when the substring's first byte appears again later in its first character. `���` is `"\x81\x81"` in Shift_JIS: ```ruby s = "���A".encode("Shift_JIS") s.index("���".encode("Shift_JIS")) # => 0 s.rindex("���".encode("Shift_JIS")) # => nil, expected 0 ``` `str_rindex` searches backwards for the substring's first byte with `memrchr`. Here that finds the second `\x81`. That byte is inside a character, so `str_rindex` moves the end of the search back to just before that character. The next `memrchr` never looks at the character's first byte, so the match that starts there is skipped. -- 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/