Project

General

Profile

Actions

Bug #19763

closed

Inconsistent error message for String#index vs String#rindex

Added by itarato (Peter Arato) 11 months ago. Updated 10 months 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 #2

Updated by nobu (Nobuyoshi Nakada) 10 months ago

  • Status changed from Open to Closed

Applied in changeset git|e2257831ab20915b839eeaff79c6ec45b498de77.


[Bug #19763] Raise same message exception for regexp

Actions

Also available in: Atom PDF

Like0
Like1Like0