Project

General

Profile

This project is closed and read-only.

Actions

Backport #1331

closed

YAML misformats hash with ruby object as key

Backport #1331: YAML misformats hash with ruby object as key

Added by bahuvrihi (Simon Chiang) over 17 years ago. Updated about 7 years ago.

Status:
Closed
Assignee:
-
[ruby-core:23062]

Description

=begin
YAML misformats the dump of hashes where the key is a user-defined ruby object. For instance:

class A; end
YAML.dump({A.new => :a})

Produces:


!ruby/object:A ? {}
: :a

Which cannot be reloaded as YAML because the question mark is in the wrong place. The correctly formatted YAML is:


? !ruby/object:A {}
: :a

I have attached a couple tests with a patch illustrating how to work around this problem using gsub. Obviously a string substitution is not a long term solution, but I hope it illustrates what needs to be fixed.
=end


Files

yaml_test.rb (992 Bytes) yaml_test.rb yaml_test.rb bahuvrihi (Simon Chiang), 03/30/2009 12:53 PM

Updated by Confusion (Ivo Wever) over 15 years ago Actions #1

=begin
This bug still exists in ruby 1.8.7 (2011-02-18 patchlevel 334). Is there a known fix or workaround that I can use? The gsub suggested by Simon seems a bit brittle.
=end

Updated by jeremyevans0 (Jeremy Evans) about 7 years ago Actions #2

  • Tracker changed from Bug to Backport
  • Project changed from 2 to 5
  • Description updated (diff)
  • Status changed from Open to Closed
  • ruby -v deleted (ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0])
Actions

Also available in: PDF Atom