aaubry/YamlDotNet

Non-decimal integer bases are not supported

jeffman opened this issue · 0 comments

I have a simple class with one int property:

class TestClass
{
    public int TestField { get; set; }
}

I try to deserialize the following YAML file:

TestField: 0x10

...using the following code:

var str = new StringReader("TestField: 0x10");
var d = new Deserializer();
var obj = d.Deserialize<TestClass>(str);

I would expect obj.TestField to have a value of 16. However, an exception is thrown during deserialization, when trying to parse "0x10" in ScalarNodeDeserializer.cs:

case TypeCode.Int32:
    value = Int32.Parse(scalar.Value, numberFormat);
    break;

It seems that the possibility of having a non-decimal base is being ignored. Many integer bases (binary, octal, hexadecimal and sexagesimal) should be allowed per the YAML spec. For reference, this works as expected in pyyaml:

>>> import yaml
>>> print yaml.load("test: 0x10")
{'test': 16}