From e8de850e6d5f9c4d9928753862b4a18147be8983 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 26 Mar 2014 11:14:44 +0000 Subject: [PATCH] encoding.c: fix encoding of dynsym * encoding.c (rb_enc_get_index): the encoding of dynamic symbol comes from fstr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- encoding.c | 3 +++ test/ruby/test_encoding.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/encoding.c b/encoding.c index df3d65cd48..b1afc87bd2 100644 --- a/encoding.c +++ b/encoding.c @@ -747,6 +747,9 @@ rb_enc_get_index(VALUE obj) obj = rb_id2str(SYM2ID(obj)); } switch (BUILTIN_TYPE(obj)) { + case T_SYMBOL: + obj = RSYMBOL(obj)->fstr; + /* fall through */ as_default: default: case T_STRING: diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb index 9a780a64c5..e3b15eb277 100644 --- a/test/ruby/test_encoding.rb +++ b/test/ruby/test_encoding.rb @@ -110,6 +110,7 @@ class TestEncoding < Test::Unit::TestCase bin = "\xff".force_encoding(Encoding::ASCII_8BIT).to_sym asc = "b".force_encoding(Encoding::ASCII_8BIT) assert_equal(Encoding::ASCII_8BIT, Encoding.compatible?(bin, asc)) + assert_equal(Encoding::UTF_8, Encoding.compatible?("\u{3042}".to_sym, ua.to_sym)) end def test_errinfo_after_autoload