[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/

Issue #19763 has been updated by nobu (Nobuyoshi Nakada). https://github.com/ruby/ruby/pull/8045 ---------------------------------------- Bug #19763: Inconsistent error message for String#index vs String#rindex https://bugs.ruby-lang.org/issues/19763#change-103791 * 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/
participants (2)
-
itarato (Peter Arato)
-
nobu (Nobuyoshi Nakada)