Project

General

Profile

Bug #1381

Confusing Encoding Error

Added by JEG2 (James Gray) about 11 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.2dev (2009-04-13) [i386-darwin9.6.0]
Backport:
[ruby-core:23208]

Description

=begin
When I reuse a Regexp object, the Encoding seems unchanged but an error message can report something different from what I am seeing:

 $ cat enc_error_bug.rb 
 re = /./
 puts re.encoding.name
 "a".encode("ASCII-8BIT") =~ re if $DEBUG
 puts re.encoding.name
 "a".encode("UTF-16BE") =~ re
 $ ruby enc_error_bug.rb 
 US-ASCII
 US-ASCII
 enc_error_bug.rb:5:in `=~': incompatible encoding regexp match (US-ASCII regexp with UTF-16BE string) (Encoding::CompatibilityError)
    from enc_error_bug.rb:5:in `<main>'
 $ ruby -d enc_error_bug.rb 
 US-ASCII
 US-ASCII
 Exception `Encoding::CompatibilityError' at enc_error_bug.rb:5 - incompatible encoding regexp match (ASCII-8BIT regexp with UTF-16BE string)
 enc_error_bug.rb:5:in `=~': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-16BE string) (Encoding::CompatibilityError)
    from enc_error_bug.rb:5:in `<main>'

Notice how the Regexp's Encoding stays US-ASCII, but the error message calls it ASCII-8BIT if I first match it as against an ASCII-8BIT String.
=end


Files

without_remember_the_previous_encoding.patch (449 Bytes) without_remember_the_previous_encoding.patch ujihisa (Tatsuhiro Ujihisa), 04/15/2009 07:52 PM
#1

Updated by ujihisa (Tatsuhiro Ujihisa) about 11 years ago

=begin
This patch fix the problem, but may cause another one. I don't understand the purpose of the original code.

=end

#2

Updated by yugui (Yuki Sonoda) almost 11 years ago

  • Assignee set to naruse (Yui NARUSE)

=begin

=end

#3

Updated by naruse (Yui NARUSE) almost 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r24197.
=end

Also available in: Atom PDF