tj/js-yaml

'a:1' and 'a:' parse to 'a'

Opened this issue · 0 comments

> 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 }