From: Brian Ford Date: 2012-01-21T13:45:18+09:00 Subject: [ruby-core:42202] [ruby-trunk - Bug #5920][Open] Encoding.compatible? gives inconsistent results with String vs Encoding arguments Issue #5920 has been reported by Brian Ford. ---------------------------------------- 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 => # 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 => # ruby-1.9.3-p0 :007 > b.valid_encoding? => true ruby-1.9.3-p0 :008 > Encoding.compatible?(a, b) => # ruby-1.9.3-p0 :009 > a << b => "abcdef" ruby-1.9.3-p0 :010 > a.encoding => # 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/