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

It's possible to get a node without a range after successfully parsing a document with a map inside a collection #573

Closed
TAGraves opened this issue Sep 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@TAGraves
Copy link

TAGraves commented Sep 3, 2024

Describe the bug
Sorry for the long winded title, but it's a bit hard to describe! I've found a case that parses successfully, but contains a YAMLMap node that does not have a range. This violates the TypeScript type definitions exposed by this library, although I'm fairly certain the issue is not with the type definitions, but with the parsing itself.

To Reproduce

const YAML = require('yaml');
const parsedDocument = YAML.parseDocument('[a:]')
const contents = parsedDocument.contents;
assert(YAML.isSeq(contents));
const firstItem = contents.items[0];
assert(firstItem);
const range = firstItem.range;
assert(range); // Uncaught AssertionError [ERR_ASSERTION]: undefined == true

According to TypeScript, range should never be null/undefined in this example, but it is in fact undefined.

Expected behaviour
Either parseDocument should fail because this is not compliant YAML, or firstItem should have a range, or the TypeScript types should correctly identify that range is optional on firstItem.

Versions (please complete the following information):

  • Environment: Node v22.6.0
  • yaml: 2.5.0

Additional context
Incidentally, the following does include a range when parsed: [{a:}].

@TAGraves TAGraves added the bug Something isn't working label Sep 3, 2024
@eemeli eemeli closed this as completed in 5b5e290 Sep 3, 2024
@eemeli
Copy link
Owner

eemeli commented Sep 3, 2024

Thank you for noticing and reporting this! There was a missing assignment of the range for the map for flow sequence pairs.

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