tj / js-yaml

CommonJS YAML Parser -- fast, elegant and tiny yaml parser for javascript
276 stars 41 forks source link

'enabled' & 'false' words cause parcer crash #20

Closed puzrin closed 8 years ago

puzrin commented 13 years ago

Example file:


---
  - mobile:
    enabled: false

when replace enable & false to another words - starts working.

puzrin commented 13 years ago

Boolean values now ok, but using "enabled" as hash name still not. Thanks for fixes.

dresende commented 13 years ago

"enabled" as well as "disabled" don't work because they are true/false tokens. Not sure this is standard..

ixti commented 12 years ago

@dresende, yes, enabled and disabled evaluate into boolean when they are used as value nodes (by YAML spec). But they are allowed to be used as keys of hashes as well as booleans. So this is absolutely valid YAML:

true: guess what
false: bools are valid
enabled: to be hash keys
disabled: even in JS

above should be parsed to JS object (according to YAML specs):

{
  true: 'guess what',
  false: 'bools are valid',
  'enabled': 'to be hash keys',
  'disabled': 'even in JS'
}
connec commented 12 years ago

I can't find 'enabled' in any YAML spec... guess it is not standard.

ixti commented 12 years ago

@connec you are right, my bad. Valid boolean values are described here: http://yaml.org/type/bool.html But the point of issue was about using such values as keywords. So for example it's absolutely valid to use "on" as a key in a mapping, and it should become boolean true. Here's an example, how they should be parsed:

http://nodeca.github.com/js-yaml/#yaml=dHJ1ZSB2YWx1ZXM6IFt5LCB5ZXMsIHRydWUsIG9uXQpmYWxzZSB2YWx1ZXM6IFtuLCBubywgZmFsc2UsIG9mZl0KYWxzbyBhcyBrZXlzOgogIC0ge3llczogMSwgbm86IDB9CiAgLSB7dHJ1ZTogMSwgZmFsc2U6IDB9CiAgLSB7b246IDEsIG9mZjogMH0=