Bug #5923

YAML serialization of binary string broken with psych engine

Added by Nathan Witmer over 2 years ago. Updated over 2 years ago.

[ruby-core:42215]
Status:Closed
Priority:Normal
Assignee:-
Category:-
Target version:-
ruby -v:ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] Backport:

Description

Using the psych engine in 1.9.3, some binary strings cannot be serialized. Instead, they result in a runtime error:

/Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:24:in `scalar': expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS (RuntimeError)

To reproduce:

$ cat a.rb

encoding: UTF-8

require "yaml"

binary = "\xC37\xA2\xC0=[\"\xE7\x06\x19\xAA1\x95\x12\xA1z"
binary.forceencoding "ascii-8bit" if binary.respondto? :force_encoding

puts "\n*** ruby #{RUBY_VERSION}"

test for ruby 1.9, both yaml engines:

if YAML.const_defined?(:ENGINE)

puts "syck engine:"
YAML::ENGINE.yamler = "syck"
puts binary.to_yaml

puts "psych engine:"
YAML::ENGINE.yamler = "psych"
puts binary.to_yaml

else

# otherwise, just dump it:
puts binary.to_yaml

end

$ rvm 1.9.3-p0,1.8.7-p352 do ruby a.rb

*** ruby 1.9.3
syck engine:
--- "\xC37\xA2\xC0=[\"\xE7\x06\x19\xAA1\x95\x12\xA1z"
psych engine:
/Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:24:in scalar': expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS (RuntimeError)
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:24:in
visitPsychNodesScalar'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in visit'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in
accept'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:19:in block in visit_Psych_Nodes_Document'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:19:in
each'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:19:in visit_Psych_Nodes_Document'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in
visit'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in accept'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:13:in
block in visit
PsychNodesStream'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:13:in each'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/emitter.rb:13:in
visitPsychNodesStream'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in visit'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in
accept'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/nodes/node.rb:46:in to_yaml'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych.rb:190:in
dump'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych/core
ext.rb:14:in psych_to_yaml'
from /Users/nathan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/syck/rubytypes.rb:170:in
to_yaml'
from a.rb:19:in `'

*** ruby 1.8.7
--- !binary |
wzeiwD1bIucGGaoxlRKheg==

History

#1 Updated by Nathan Witmer over 2 years ago

My apologies, this issue has been fixed in 1.9.3-head. Awaiting a release!

#2 Updated by Marc-Andre Lafortune over 2 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF