Why is YAML.load returning an invalid numeric value?

Why is YAML.load returning an invalid value?

ruby-1.9.2-p0 :006 > a = YAML.load('merchant_id: 014213245611111')
 => {"merchant_id"=>843333440073} 
ruby-1.9.2-p0 :007 > a["merchant_id"]
 => 843333440073 

I'm on ruby ​​1.9.2-p0, rvm, ubuntu10.10, 64bit.

+3
source share
2 answers

The YAML parser treats "014213245611111" as an octal (base-8) number, not a string. Wrap it in quotation marks to keep leading 0.

+7
source

A leading value of 0 means an octal number - 14213245611111 an octal value = 843333440073. If you need leading zeros, you should use a string value instead of a numeric one.

+3
source

All Articles