psych
psych copied to clipboard
yaml parsing is wrong when key's value has leading colon
replication steps:
ruby -ryaml -e "a = YAML.load('servers: ::ffff:10.10.10.1'); puts a; puts a['servers']"
{"servers"=>:":ffff:10.10.10.1"}
:ffff:10.10.10.1
expected:
{"servers"=>"::ffff:10.10.10.1"}
::ffff:10.10.10.1
actual result:
{"servers"=>:":ffff:10.10.10.1"}
:ffff:10.10.10.1
Environment:
ruby --version
ruby 2.7.0p0
gem list yaml
yaml (0.3.0)
Python yaml works as expected:
python3.9 -c 'import yaml; a=yaml.safe_load("servers: ::ffff:10.10.10.1"); print(a); print(a["servers"]);'
{'servers': '::ffff:10.10.10.1'}
::ffff:10.10.10.1
I guess this is because Python doesn't have the concept of a Symbol like Ruby does?
As a work-around, this should work (untested):
ruby -ryaml -e "a = YAML.load('servers: "::ffff:10.10.10.1"'); puts a; puts a['servers']"
I'm not sure what to do about this. I'm sure there are Ruby users that well expect symbols in this case so I don't want to change the behavior.