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

Implicit map keys need to be followed by map values #120

Closed
notiv-nt opened this issue Sep 18, 2019 · 3 comments · Fixed by armand-janssen/openapi-transformer#36 or armand-janssen/openapi-transformer#41
Labels
bug Something isn't working

Comments

@notiv-nt
Copy link

notiv-nt commented Sep 18, 2019

Error:

image

Ok:

image
image

The error appears only if the very last character is :

I'm not so sure it should be?

const YAML = require('yaml');
const text = require('fs').readFileSync('./doc.yaml', { encoding: 'utf8' });
const cst = YAML.parseCST(text);
const doc = new YAML.Document();

let a = doc.parse(cst[0]);

console.dir(a.errors); //
test:
  - test1: test1
    test2:

https://repl.it/@MikeWild/MammothFortunateDatamining

Yaml v 1.6.0

@eemeli eemeli added the bug Something isn't working label Sep 21, 2019
@eemeli eemeli closed this as completed in c6adfa8 Sep 21, 2019
@eemeli
Copy link
Owner

eemeli commented Sep 21, 2019

I'm pretty sure that this was indeed a bug in the CST parser. Specifically, it was only terminating a plain-value node at a : if the subsequent character was whitespace, but not if it the input ended there. Now it does. This changes the handling of the following minimal case:

// before
YAML.parse('a:') // 'a:'

// after
YAML.parse('a:') // { a: null }

// unchanged
YAML.parse('a:\n') // { a: null }

The specific spec construct that's being handled here is c-l-block-map-implicit-value(n) which can, when you trace all of its possible values, match the following:

c-l-block-map-implicit-value(n) ::= “:” ( s-l+block-node(n,block-out) | ( e-node s-l-comments ) )
e-node ::= e-scalar ::= /* Empty */
s-l-comments ::= ( s-b-comment | /* Start of line */ ) l-comment*
s-b-comment ::= ( s-separate-in-line c-nb-comment-text? )? b-comment
b-comment ::= b-non-content | /* End of file */

I'd missed the final step there, which allows for “:” /* End of file */ to be considered a valid implicit value.

@notiv-nt
Copy link
Author

@eemeli can you make a release ?

@eemeli
Copy link
Owner

eemeli commented Sep 24, 2019

@notiv-nt Will do, once #122 is resolved.

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
2 participants