YAML bug with : in strings?

G

Guillaume Marcais

$ irb
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> YAML::load(":not_a_symbol".to_yaml).class
=> Symbol

The original object was a string starting with ':', not a symbol.

Guillaume.
 
A

Ara.T.Howard

$ irb
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> YAML::load(":not_a_symbol".to_yaml).class
=> Symbol

The original object was a string starting with ':', not a symbol.

Guillaume.

you can get around this (if it is not a bug) by quoting the string:

[nrt@bligh filters]$ ruby -r yaml -e 'p YAML::load(%q(":not_a_symbol").to_yaml).class'
String

regards.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================
 
J

Joel VanderWerf

Guillaume said:
$ irb
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> YAML::load(":not_a_symbol".to_yaml).class
=> Symbol

The original object was a string starting with ':', not a symbol.

Guillaume.

What version? I get String:

$ ruby -v -r yaml -e 'p YAML::load(":not_a_symbol".to_yaml).class'
ruby 1.9.0 (2004-10-17) [i686-linux]
String

The string has been escaped by #to_yaml

$ ruby -r yaml -e 'puts ":not_a_symbol".to_yaml'
--- ":not_a_symbol"
 
G

Guillaume Marcais

What version? I get String:

I guess I should have given the version in my original post:

$ irb -v
irb 0.9(02/07/03)
$ ruby -v
ruby 1.8.1 (2004-04-05) [i686-linux]
$ ruby -v -r yaml -e 'p YAML::load(":not_a_symbol".to_yaml).class'
ruby 1.9.0 (2004-10-17) [i686-linux]
String

Good. It has been fixed.
The string has been escaped by #to_yaml

$ ruby -r yaml -e 'puts ":not_a_symbol".to_yaml'
--- ":not_a_symbol"

The problem was loading, not emitting:
$ ruby -v -ryaml -e 'puts ":not_a_symbol".to_yaml'
ruby 1.8.1 (2004-04-05) [i686-linux]
--- ":not_a_symbol"

$ ruby -v -ryaml -e 'puts YAML::load("--- \":not_a_symbol\"").class'
ruby 1.8.1 (2004-04-05) [i686-linux]
Symbol

Thanks,
Guillaume.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top