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

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

Open
grzm opened this issue Sep 16, 2022 · 0 comments

Comments

@grzm
Copy link

grzm commented Sep 16, 2022

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.

MariteSomEnergia added a commit to Som-Energia/opendata-ui that referenced this issue Oct 17, 2023
Due to a bug in js-yaml, non-octal 0 padded numeric codes
are parsed as number instead strings and we are losing
the code zero padding.

nodeca/js-yaml#684

Co-authored-by: David García Garzón <david.garcia@somenergia.coop>
vokimon added a commit to Som-Energia/somenergia-tomatic that referenced this issue Mar 11, 2024
workarround for jsyaml bug on numeric strings with leading zeroes

See nodeca/js-yaml#684
vokimon added a commit to Som-Energia/somenergia-tomatic that referenced this issue Mar 12, 2024
workarround for jsyaml bug on numeric strings with leading zeroes

See nodeca/js-yaml#684
vokimon added a commit to Som-Energia/somenergia-tomatic that referenced this issue Mar 12, 2024
workarround for jsyaml bug on numeric strings with leading zeroes

See nodeca/js-yaml#684
vokimon added a commit to Som-Energia/somenergia-tomatic that referenced this issue Mar 12, 2024
workarround for jsyaml bug on numeric strings with leading zeroes

See nodeca/js-yaml#684
vokimon added a commit to Som-Energia/somenergia-tomatic that referenced this issue Mar 12, 2024
workarround for jsyaml bug on numeric strings with leading zeroes

See nodeca/js-yaml#684
vokimon added a commit to Som-Energia/somenergia-tomatic that referenced this issue Mar 14, 2024
workarround for jsyaml bug on numeric strings with leading zeroes

See nodeca/js-yaml#684
vokimon added a commit to Som-Energia/somenergia-tomatic that referenced this issue Mar 22, 2024
workarround for jsyaml bug on numeric strings with leading zeroes

See nodeca/js-yaml#684
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

1 participant