From: James Gray Date: 2009-04-15T06:32:32+09:00 Subject: [ruby-core:23208] [Bug #1381] Confusing Encoding Error Bug #1381: Confusing Encoding Error http://redmine.ruby-lang.org/issues/show/1381 Author: James Gray Status: Open, Priority: Normal Category: M17N, Target version: 1.9.2 ruby -v: ruby 1.9.2dev (2009-04-13) [i386-darwin9.6.0] 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 `
' $ 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 `
' 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. ---------------------------------------- http://redmine.ruby-lang.org