Project

General

Profile

Actions

Bug #19763

closed

Inconsistent error message for String#index vs String#rindex

Added by itarato (Peter Arato) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:114119]

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

Also available in: Atom PDF

Like0
Like1Like0