Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-decimal integer bases are not supported #113

Closed
jeffman opened this issue Dec 11, 2014 · 0 comments
Closed

Non-decimal integer bases are not supported #113

jeffman opened this issue Dec 11, 2014 · 0 comments

Comments

@jeffman
Copy link
Contributor

jeffman commented Dec 11, 2014

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}
jeffman added a commit to jeffman/YamlDotNet that referenced this issue Sep 14, 2015
Addresses issue aaubry#113. Adds basic support for deserializing scalar integers
written in binary, octal, decimal, hex, and base 60, as allowed in the YAML
specification; see http://yaml.org/type/int.html. Adds unit tests for each
of these bases as well.
@aaubry aaubry closed this as completed Aug 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants