Actions
Bug #1381
closedConfusing Encoding Error
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
Updated by ujihisa (Tatsuhiro Ujihisa) over 15 years ago
- File without_remember_the_previous_encoding.patch without_remember_the_previous_encoding.patch added
=begin
This patch fix the problem, but may cause another one. I don't understand the purpose of the original code.
=end
Updated by naruse (Yui NARUSE) over 15 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
=begin
Applied in changeset r24197.
=end
Actions
Like0
Like0Like0Like0