diff options
-rw-r--r-- | ext/psych/parser.c | 8 | ||||
-rw-r--r-- | test/psych/test_encoding.rb | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 76ca4dd..f028447 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -177,9 +177,11 @@ static VALUE parse(VALUE self, VALUE yaml) break; case YAML_SEQUENCE_START_EVENT: { - VALUE anchor = event.data.sequence_start.anchor ? - rb_str_new2((const char *)event.data.sequence_start.anchor) : - Qnil; + VALUE anchor = Qnil; + if(event.data.sequence_start.anchor) { + anchor = rb_str_new2((const char *)event.data.sequence_start.anchor); + rb_enc_associate_index(anchor, encoding); + } VALUE tag = Qnil; if(event.data.sequence_start.tag) { diff --git a/test/psych/test_encoding.rb b/test/psych/test_encoding.rb index d97856f..4c333e7 100644 --- a/test/psych/test_encoding.rb +++ b/test/psych/test_encoding.rb @@ -50,6 +50,13 @@ module Psych assert_encodings @utf8, @handler.strings end + def test_list_anchor + list = %w{ a b } + list << list + @parser.parse(Psych.dump(list)) + assert_encodings @utf8, @handler.strings + end + private def assert_encodings encoding, strings strings.each do |str| |