[#41916] Proposal: Bitmap Marking GC — Narihiro Nakamura <authornari@...>

Hi.

18 messages 2012/01/05

[#41941] [ruby-trunk - Bug #5851][Open] make check fails when compiling with GCC 4.7 - *** longjmp causes uninitialized stack frame *** — Vit Ondruch <v.ondruch@...>

12 messages 2012/01/06

[#41979] [ruby-trunk - Bug #5865][Open] Exception#== should return false if the classes differ — Hiro Asari <asari.ruby@...>

10 messages 2012/01/08

[#42003] [ruby-trunk - Bug #5871][Open] regexp \W matches some word characters when inside a case-insensitive character class — Gareth Adams <gareth@...>

14 messages 2012/01/09

[#42016] [ruby-trunk - Feature #5873][Open] Adopt FFI over DL — Heesob Park <phasis@...>

15 messages 2012/01/10

[#42149] [ruby-trunk - Feature #5899][Open] chaining comparsions. — Ondrej Bilka <neleai@...>

12 messages 2012/01/16

[#42164] [ruby-trunk - Feature #5903][Open] Optimize st_table (take 2) — Yura Sokolov <funny.falcon@...>

18 messages 2012/01/17

[ruby-core:42209] [ruby-trunk - Bug #5920] Encoding.compatible? gives inconsistent results with String vs Encoding arguments

From: Yui NARUSE <naruse@...>
Date: 2012-01-21 12:26:11 UTC
List: ruby-core #42209
Issue #5920 has been updated by Yui NARUSE.


It is intended.

The original meaning of Encoding.compatible?(str1, str2) is the encoding of concatenated string.
In other codes, it is
  str = str1.dup.concat str2
  str.encoding <- this!

If an object is an encoding object, it is considered as a string which is valid, has the encoding, and not ASCII only.
For example UTF-8, Encoding::UTF_8 is considered as a string like "\u3042".
----------------------------------------
Bug #5920: Encoding.compatible? gives inconsistent results with String vs Encoding arguments
https://bugs.ruby-lang.org/issues/5920

Author: Brian Ford
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]


Is this a bug? If I pass two strings that have the same encodings as the Encoding instances I pass directly, I get different results.

$ irb
ruby-1.9.3-p0 :001 > Encoding.compatible?(Encoding::EUC_JP, Encoding::UTF_8)
 => nil 
ruby-1.9.3-p0 :002 > a = "abc".encode "euc-jp"
 => "abc" 
ruby-1.9.3-p0 :003 > a.encoding
 => #<Encoding:EUC-JP> 
ruby-1.9.3-p0 :004 > a.valid_encoding?
 => true 
ruby-1.9.3-p0 :005 > b = "def".encode "utf-8"
 => "def" 
ruby-1.9.3-p0 :006 > b.encoding
 => #<Encoding:UTF-8> 
ruby-1.9.3-p0 :007 > b.valid_encoding?
 => true 
ruby-1.9.3-p0 :008 > Encoding.compatible?(a, b)
 => #<Encoding:EUC-JP> 
ruby-1.9.3-p0 :009 > a << b
 => "abcdef" 
ruby-1.9.3-p0 :010 > a.encoding
 => #<Encoding:EUC-JP> 
ruby-1.9.3-p0 :011 > a.valid_encoding?
 => true 

If this is not a bug, could someone please explain the rationale behind the behavior.

Thanks,
Brian



-- 
http://bugs.ruby-lang.org/

In This Thread