Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
go-yaml should handle invalid integers as strings #157
Comments
This was referenced Feb 9, 2016
jbiel
commented
Aug 5, 2016
|
This is an issue for me. |
qix
commented
Oct 6, 2016
|
I'm seeing this issue in an unlucky git commit hash that contained only digits Python serializes it to an unquoted string, which I don't like but is technically okay I believe.
|
pushed a commit
to vinzenz/yaml
that referenced
this issue
Nov 3, 2016
pushed a commit
to vinzenz/yaml
that referenced
this issue
Nov 3, 2016
CpuID
commented
Nov 18, 2016
|
This would be awesome to have resolved, docker-compose.yml ports are recommended to be defined as strings instead of integers. |
dsegan
commented
Jan 20, 2017
|
FWIW, the spec seems to confirm this is wrong: http://yaml.org/spec/1.2/spec.html#id2803828 Integers are 0 | -? [1-9] [0-9]* |
|
Merged #171. |
niemeyer
closed this
Jan 25, 2017
howbazaar
commented
Feb 14, 2017
|
PR #171 doesn't actually fix this issue. |
|
The regex in #171 uses: var yamlStyleFloat = regexp.MustCompile( Which would be "0" or negative or must not start with a 0 character. IOW, Octal integers are disallowed. As is '-0'. The YAML spec also doesn't allow a leading "+" sign. For floats it allows: Which again doesn't allow a leading +, only in the exponent section, and it also doesn't allow a leading 0. |
howbazaar
referenced this issue
Feb 15, 2017
Open
Update the yamlStyleFloat regex for special case. #241
That's not actually the case. That shows the canonical form of an integer. The actual regexp is defined in section 10.3.2 and is The actual bug here is that go-yaml is interpreting the number as octal (YAML uses a However, it seems that many existing parsers do indeed treat "01234" as a string, not an integer, despite the spec, so it may be wise to do that anyway. |
mbruzek commentedFeb 9, 2016
Starting a numeric sequence with zero indicates an octal number. So 01234567 == 342391 (base 10). Numeric sequences that start with zero and contain numbers higher than 7 are invalid integers and should be parsed as strings even when they do not have quotes around them.
01182252 is not a valid octal integer and should be treated as a string. go-yaml attempts to parse the numeric sequence as an integer and this is incorrect.
Several yaml validators and other language yaml packages handle this case correctly such as the Python ruamel package and on line parsers http://yaml-online-parser.appspot.com/