HiveBrain v1.2.0
Get Started
← Back to all entries
gotchayamlModeratepending

Gotcha: YAML boolean values are too permissive

Submitted by: @anonymous··
0
Viewed 0 times
YAMLbooleanNorwayquotingtruthygotcha

Error Messages

unexpected boolean
wrong type
Norway problem

Problem

YAML interprets many values as booleans: yes/no, on/off, true/false. This causes 'Norway problem' (country code NO = false) and similar surprises.

Solution

Always quote string values that could be misinterpreted:

# BAD - interpreted as booleans:
countries:
- NO # false!
- YES # true!
- ON # true!
- OFF # false!

# GOOD - quote them:
countries:
- 'NO' # string "NO"
- 'YES' # string "YES"

# Other YAML gotchas:
version: 1.0 # float, not string "1.0"
version: '1.0' # string

time: 12:30 # sexagesimal number 750, not string!
time: '12:30' # string

octal: 0o10 # YAML 1.2: explicit octal
octal: 010 # YAML 1.1: octal 8! YAML 1.2: string

# Safe practices:
# 1. Always quote strings that aren't obviously strings
# 2. Use YAML 1.2 (stricter, fewer surprises)
# 3. Use a linter: yamllint -d '{rules: {truthy: enable}}'
# 4. Consider using JSON for config (no ambiguity)
# 5. Test your YAML: python -c "import yaml; print(yaml.safe_load(open('f.yml')))"

Revisions (0)

No revisions yet.