Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

'a:1' and 'a:' parse to 'a' #58

Open
matiasdahl opened this issue Jul 9, 2015 · 0 comments
Open

'a:1' and 'a:' parse to 'a' #58

matiasdahl opened this issue Jul 9, 2015 · 0 comments

Comments

@matiasdahl
Copy link

> require('yaml').eval('a:1')
'a'
> require('yaml').eval('a: ')
'a'
> require('yaml').eval('a:')
'a'
> require('yaml').version
'0.2.3'

Inputs of this type are discussed in the YAML standard (http://www.yaml.org/spec/1.2/spec.html, between examples 7.16 and 7.17). Specifically:

  • 'a:1' is a plain scalar and not a key: value pair.
  • the value may be empty in key: value pairs.

Thus (and if I read this correctly) 'a:1' should parse to the string 'a:1' and 'a:' should parse to the key: value pair {a: null}. This is also the output of other YAML parsers:

Online YAML parser (http://yaml-online-parser.appspot.com/)

based on pyyaml:

'a:1' -> 'a:1'
'a: ' -> {'a': null}
'a:' -> {'a': null}
js-yaml (https://github.com/nodeca/js-yaml)
> require('js-yaml').safeLoad('a:1')
'a:1'
> require('js-yaml').safeLoad('a: ')
{ a: null }
> require('js-yaml').safeLoad('a:')
{ a: null }
yamljs (https://github.com/jeremyfa/yaml.js)
> require('yamljs').parse('a:1')
'a:1'
> require('yamljs').parse('a: ')
{ a: null }
> require('yamljs').parse('a:')
{ a: null }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant