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

Parse/stringify of keys containing ... #431

Closed
f4b1ux opened this issue Dec 28, 2022 · 3 comments
Closed

Parse/stringify of keys containing ... #431

f4b1ux opened this issue Dec 28, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@f4b1ux
Copy link

f4b1ux commented Dec 28, 2022

Short Description
The library correctly parse a document with a key containing ... in it, if placed in single or double quotes. But when you stringify the obtained json, the result is a key containing ... but without quotes, so when you try to parse it again, library returns a "Unexpected scalar at node end at...".
In YAML ... is document stop token (the counterpart to ---).

To Reproduce

const YAML = require('yaml);

const parsed = YAML.parse("'... this is a test': this is the value");
const stringified = YAML.stringify(parsed);
const reparsed = YAML.parse(stringified)

Expected behaviour
Keys containing token such as "..." or "---" should be automatically placed in quotes on stringify.

Versions (please complete the following information):

  • Environment: Node 18.12.1
  • yaml: 2.2.0

Additional context
A workaround is to specify defaultKeyType option inside stringify options to QUOTE_SINGLE or QUOTE_DOUBLE. This causes that ALL keys will be single (or double) quoted.

@f4b1ux f4b1ux added the bug Something isn't working label Dec 28, 2022
@f4b1ux
Copy link
Author

f4b1ux commented Dec 28, 2022

I also noticed that using yaml parseDocument instead of parse function works better.

const YAML = require('yaml');

const parsed = YAML.parseDocument("'... this is a test': this is the value");
const stringified = YAML.stringify(parsed);
const reparsed = YAML.parse(stringified);

@f4b1ux f4b1ux changed the title Parse/stringify of keys containing "..." Parse/stringify of keys containing ... Dec 28, 2022
@eemeli
Copy link
Owner

eemeli commented Dec 28, 2022

Confirming this is a bug; this should not fail, but it does:

YAML.parse(YAML.stringify({ '... x': 42 }))

@eemeli eemeli closed this as completed in c8551eb Dec 30, 2022
@eemeli
Copy link
Owner

eemeli commented Dec 30, 2022

Fix released in v2.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants