3 ms·
Even if you have a YAML 1.2 parser, here's another one: In [1]: v = "\N{PILE OF POO}" In [2]: yaml.load(json.dumps(v), yaml.SafeLoader) == v Out[2]: Fal
by deathanatos 1y ago
Even if you have a YAML 1.2 parser, here's another one:
In [1]: v = "\N{PILE OF POO}"
In [2]: yaml.load(json.dumps(v), yaml.SafeLoader) == v
Out[2]: False
The specification is woefully underspecified with regards to Unicode escapes. E.g., it uses "Unicode characters" practically throughout, a construct that doesn't exist in Unicode & (AFAICT) is not defined by YAML. A reasonable interpretation of that leads us to
\uabcd
(which the spec says is "Escaped 16-bit Unicode character.") …decoding to the USV with value 0xabcd. But that's not compatible with JSON.
(PyYAML is not the only library with that reading of the spec, either. Rust's will outright error on the input here, as its `str` type is equivalent to [USV], whereas Python's `str` is not. (The value Python decodes in the example above is a representable but illegal value.))