YAML: The Norway Problem

Earlier this week, Haroen Viaene posted this tweet about YAML: worst part of yaml: https://yaml.org/type/bool.html — Haroen Viaene (@haroenv) January 10, 2022 The linked-to page contains the documentation on what defines a boolean in YAML, and details that it can be parsed using this regex: y|Y|yes|Yes|YES|n|N|no|No|NO |true|True|TRUE|false|False|FALSE |on|On|ON|off|Off|OFF The reason to why this is problematic …


This content originally appeared on Bram.us and was authored by Bramus!

Earlier this week, Haroen Viaene posted this tweet about YAML:

The linked-to page contains the documentation on what defines a boolean in YAML, and details that it can be parsed using this regex:

y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF

~

The reason to why this is problematic in some cases, is “The Norway Problem” YAML has: when you abbreviate Norway to its ISO 3116-1 ALPHA-2 form NO, YAML will return false when parsing it:

countries:
- GB
- IE
- FR
- DE
- NO
>>> from pyyaml import load
>>> load(the_configuration)
{'countries': ['GB', 'IE', 'FR', 'DE', False]}

👉 The solution is to either escape these values in double quotes, or to use a library — such as StrictYAML for Python — that won’t convert NO to False.

~

Other problematic values in YAML are version numbers that end in .0 and a lastname such as Null. By default these get converted to numbers or NULL respectively.

The Norway Problem →
StrictYAML →


This content originally appeared on Bram.us and was authored by Bramus!


Print Share Comment Cite Upload Translate Updates
APA

Bramus! | Sciencx (2022-01-11T21:14:33+00:00) YAML: The Norway Problem. Retrieved from https://www.scien.cx/2022/01/11/yaml-the-norway-problem/

MLA
" » YAML: The Norway Problem." Bramus! | Sciencx - Tuesday January 11, 2022, https://www.scien.cx/2022/01/11/yaml-the-norway-problem/
HARVARD
Bramus! | Sciencx Tuesday January 11, 2022 » YAML: The Norway Problem., viewed ,<https://www.scien.cx/2022/01/11/yaml-the-norway-problem/>
VANCOUVER
Bramus! | Sciencx - » YAML: The Norway Problem. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/11/yaml-the-norway-problem/
CHICAGO
" » YAML: The Norway Problem." Bramus! | Sciencx - Accessed . https://www.scien.cx/2022/01/11/yaml-the-norway-problem/
IEEE
" » YAML: The Norway Problem." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2022/01/11/yaml-the-norway-problem/. [Accessed: ]
rf:citation
» YAML: The Norway Problem | Bramus! | Sciencx | https://www.scien.cx/2022/01/11/yaml-the-norway-problem/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.