JuliaData / YAML.jl

Parse yer YAMLs
Other
128 stars 45 forks source link

Incorrect handling of special keys when writing YAML files #236

Closed dalum closed 2 months ago

dalum commented 2 months ago

I've run into some issues where the writer produces files that cannot be parsed again, when string keys are present, which start with special characters. A few examples are:

for char in [
    "{", "}", "[", "]", "&", "*", "#", "?", "|", "-", "<", ">",
    "=", "!", "%", "@", ":", "`", ",", "'", "\"",
]
    d = Dict(char => 0.0)
    @test YAML.load(YAML.yaml(d)) == d
end

As an example, YAML.yaml(Dict(">" => 0.0)) produces:

>: 0.0

which does not parse.

By comparison, Python's YAML writer successfully handles these by quoting the key:

In : yaml.dump({">": 0.0})
Out: "'>': 0.0\n"