From: "itarato (Peter Arato) via ruby-core" Date: 2023-07-08T14:53:22+00:00 Subject: [ruby-core:114119] [Ruby master Bug#19763] Inconsistent error message for String#index vs String#rindex Issue #19763 has been reported by itarato (Peter Arato). ---------------------------------------- Bug #19763: Inconsistent error message for String#index vs String#rindex https://bugs.ruby-lang.org/issues/19763 * Author: itarato (Peter Arato) * Status: Open * Priority: Normal * ruby -v: 3.3.0 * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- `String#index` and `String#rindex` yields different error messages when used with a `Regexp` argument: ```ruby 'abc'.force_encoding("ISO-2022-JP").index(/���/) ``` Prints: `incompatible character encodings: ISO-2022-JP and UTF-8 (Encoding::CompatibilityError)` ```ruby 'abc'.force_encoding("ISO-2022-JP").rindex(/���/) ``` Prints: `incompatible encoding regexp match (UTF-8 regexp with ISO-2022-JP string) (Encoding::CompatibilityError)` Looking at a few other use cases (eg `String#byteindex`, `String#byterindex`) Ruby seems to use the message `incompatible encoding regexp match ` when encoding is checked between a String and a Regexp instance. Is this a bug for `String#index`? -- 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/postorius/lists/ruby-core.ml.ruby-lang.org/