Skip to content

Parsing non-octal leading-zero numeric strings with YAML 1.1 directive should be strings #684

@grzm

Description

@grzm

In YAML 1.1, numeric scalars with leading zeros that include characters 8 or 9 do not need to be quoted. For example, the scalar 083 must be a string as it can't be a valid octal value. In YAML 1.2, 083 is interpreted as a number.

My understanding is that a YAML directive in a YAML document should allow a YAML processor to distinguish between these specifications. For example, given the following document:

%YAML 1.1
--- 083

The yaml processor should know to interpret the scalar 083 as the string "083" instead of as the number 83. js-yaml interprets the value as the number 83. Here's an example package.json and index.js

{
  "dependencies": {
    "js-yaml": "^4.1.0"
  }
}
const yaml = require('js-yaml');

const unquoted = "%YAML 1.1\n--- 083\n";
const quoted = "%YAML 1.1\n--- '083'\n";

const vals = [unquoted, quoted];
for (const val of vals) {
    console.log(">>>START<<<");
    console.log(val);
    console.log(">>>END<<<");
    console.log(yaml.load(val));
}
% node index.js
>>>START<<<
%YAML 1.1
--- 083

>>>END<<<
83
>>>START<<<
%YAML 1.1
--- '083'

>>>END<<<
083

I'd expect both of these to parse as the string "083" given the %YAML 1.1 directive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions