Actions
Bug #19763
closedInconsistent error message for String#index vs String#rindex
Description
String#index
and String#rindex
yields different error messages when used with a Regexp
argument:
'abc'.force_encoding("ISO-2022-JP").index(/わ/)
Prints: incompatible character encodings: ISO-2022-JP and UTF-8 (Encoding::CompatibilityError)
'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
?
Actions
Like0
Like1Like0