Consider always quoting strings that look like numbers

Issue #554 resolved
Lee Read created an issue

Snakeyaml 1.30 fixed a resolver bug to recognize string 083 as a string. As such, it is now emitted like any other string, without quotes.

This can cause issues for some YAML 1.2 parsers which will interpret an unquoted 083 as integer 83.

I propose that we always emit strings that start with zero and look like numbers with quotes.

This would mean that string 083 would be emitted as '083'.

I will follow up with a PR for your consideration.

Comments (3)

  1. Andrey Somov

    Always emit numberish strings with quotes

    It is perfectly valid to emit most strings without quotes in YAML 1.1.

    For example string 083 can be emitted as 083. Although it starts with a zero, it is not valid octal, and therefore must be a string and can be emitted without quotes.

    But a problem will occur if this unquoted 083 is read by some YAML 1.2 parsers, they will read it as integer 83. To appease these parsers, snakeyaml now emits any string that starts with a 0 and looks numberish with quotes.

    This means that string 083 will be emitted as '083'.

    Addresses #554

    → <<cset 80827798f06a>>

  2. Log in to comment