Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All keys are printed in plain style #124

Closed
nhz2 opened this issue Oct 3, 2022 · 1 comment
Closed

All keys are printed in plain style #124

nhz2 opened this issue Oct 3, 2022 · 1 comment

Comments

@nhz2
Copy link

nhz2 commented Oct 3, 2022

Currently all keys are just converted to strings and printed, (except for nothing)

This assumes that keys don't have any problematic characters for example " #" and are shorter than 1024 Unicode characters.

YAML.jl/src/writer.jl

Lines 67 to 74 in 6683ecf

# print a single key-value pair
function _print(io::IO, pair::Pair, level::Int=0, ignore_level::Bool=false)
key = if pair[1] === nothing
"null" # this is what the YAML parser interprets as 'nothing'
else
string(pair[1]) # any useful case
end
print(io, _indent(key * ":", level, ignore_level)) # print the key

I think there should be some function to check if a key is a valid implicit key in plain style, otherwise it should be in double quoted style.

Here is an example that errors.

YAML.load(YAML.yaml(Dict(["#a"=>"b"])))
@nhz2
Copy link
Author

nhz2 commented Jul 31, 2024

Partially fixed by #237

@nhz2 nhz2 closed this as completed Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant