Hash#to_yaml does not work with Ranges as keys #2941

Closed
snex opened this Issue Feb 12, 2014 · 2 comments

Comments

Projects
None yet
3 participants

snex commented Feb 12, 2014

rubinius 2.2.4 (2.1.0 fd07f67 2014-02-01 JI) [x86_64-darwin13.0.0]
Darwin ... 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64
rvm 1.25.16 (master) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]

> require 'yaml'
=> false
> str = {(0..1) => 1}.to_yaml
=> "--- \n!ruby/range ? \n  begin: 0\n  end: 1\n  excl: false\n  :@begin: 0\n  :@end: 1\n  :@excl: false\n: 1\n\n"
> YAML.load(str)
ArgumentError: syntax error on line 2, col -1: `  begin: 0
  end: 1
  excl: false
  :@begin: 0
  :@end: 1
  :@excl: false
: 1

'

Syck (the default YAML engine of rubinius) emits question mark (the complex key indicator) to the end of line, apparently incorrect.
As a workaround, just install psych gem, then this issue will disappear.

# bin/rbx -S gem install psych
localhost:/home/nanami/rubinius # bin/rbx
irb(main):003:0> require 'yaml'
=> true
irb(main):004:0>
irb(main):005:0* str = {(0..1) => 1}.to_yaml
=> "---\n? !ruby/range\n  begin: 0\n  end: 1\n  excl: false\n: 1\n"
irb(main):006:0> YAML.load(str)
=> {0..1=>1}
Owner

YorickPeterse commented Feb 18, 2015

This no longer occurs as of 4417909 as we (since a short while) now use Psych as the default YAML engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment