What is the Norway Bug?
A Classic Trap in YAML Parsing
The Norway Bug is one of the most common yet easily overlooked issues in YAML parsing. Named after Norway's country code "NO", but its impact extends far beyond just this case.
⚠️Problem Description
The YAML specification defines many strings that are automatically interpreted as boolean values, which often conflicts with developer expectations. When you write `country: NO`, the YAML parser interprets `NO` as the boolean `false`, not the string `"NO"`.
Problem Examples
Here are some common Norway Bug examples:
❌Original YAML (problematic)
country: NO # Parsed as false enabled: Yes # Parsed as true debug: On # Parsed as true region: off # Parsed as false status: TRUE # Parsed as true
✅Fixed KYAML
{ "country": "NO", # Explicit string "enabled": "Yes", # Explicit string "debug": "On", # Explicit string "region": "off", # Explicit string "status": "TRUE", # Explicit string }
Affected Values
These strings are interpreted as boolean values according to the YAML specification:
Values interpreted as true
true
True
TRUE
yes
Yes
YES
on
On
ON
Values interpreted as false
false
False
FALSE
no
No
NO
off
Off
OFF
Note:These values are case-insensitive and can be partial uppercase combinations.
Impact Scope
Problems that Norway Bug can cause:
- 1Country codes in config files parsed incorrectly
- 2String representations of switch states unexpectedly converted
- 3Type errors during data import
- 4Unexpected behavior in production
- 5Difficult debugging since errors aren't obvious
Solutions
Several ways to avoid the Norway Bug:
1. Add Quotes
The most direct method is to quote these values.
country: "NO" # Explicitly specify as string
enabled: "Yes" # Avoid boolean conversion
2. Use KYAML Format
KYAML forces all strings to use double quotes, completely avoiding this issue.
{
"country": "NO",
"enabled": "Yes",
}
3. Change Value Representation
Use more explicit values to avoid ambiguity.
country: Norway
enabled: true # If you actually want a boolean
🚀KYAML Advantages
KYAML completely solves the Norway Bug through:
- ✓All string values are surrounded by double quotes
- ✓Explicit type representation, reducing ambiguity
- ✓Automatic detection and fixing of potential Norway Bugs
- ✓Preserving original data intent
How to Prevent
In daily development, you can:
- 1Use our online converter to check YAML files
- 2Integrate KYAML validation in CI/CD pipelines
- 3Establish YAML writing standards for teams
- 4Use editor plugins that support Norway Bug detection