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

TOML: Dict inside mixed vector produces invalid TOML #45340

Closed
fonsp opened this issue May 17, 2022 · 0 comments · Fixed by #47876
Closed

TOML: Dict inside mixed vector produces invalid TOML #45340

fonsp opened this issue May 17, 2022 · 0 comments · Fixed by #47876
Labels
bug Indicates an unexpected problem or unintended behavior TOML

Comments

@fonsp
Copy link
Member

fonsp commented May 17, 2022

julia> import TOML

julia> d =  Dict("b" => Any[Dict("a" =>  222, "d" => 333)]);

julia> TOML.print(d)
[[b]]
a = 222
d = 333

julia> d =  Dict("b" => Any[111, Dict("a" =>  222, "d" => 333)]);

julia> TOML.print(d)
b = [111, a = 222
d = 333
]

This is invalid TOML syntax.


It looks like we have code to prevent mixing Dicts and other types in a vector, but it only throws an error if the first element is a Dict:

julia> d =  Dict("b" => Any[Dict("f" => 000), 111, Dict("a" =>  222, "d" => 333)]);

julia> TOML.print(d)
[[b]]
f = 0
[[b]]
ERROR: array should contain only tables
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] _print(f::Nothing, io::Base.TTY, a::Dict{String, Vector{Any}}, ks::Vector{String}; indent::Int64, first_block::Bool, sorted::Bool, by::Function)
   @ TOML.Internals.Printer /Applications/Julia-1.7 x86.app/Contents/Resources/julia/share/julia/stdlib/v1.7/TOML/src/print.jl:160
 [3] #print#13
   @ /Applications/Julia-1.7 x86.app/Contents/Resources/julia/share/julia/stdlib/v1.7/TOML/src/print.jl:168 [inlined]
 [4] print(a::Dict{String, Vector{Any}}; sorted::Bool, by::Function)
   @ TOML.Internals.Printer /Applications/Julia-1.7 x86.app/Contents/Resources/julia/share/julia/stdlib/v1.7/TOML/src/print.jl:171
 [5] print(a::Dict{String, Vector{Any}})
   @ TOML.Internals.Printer /Applications/Julia-1.7 x86.app/Contents/Resources/julia/share/julia/stdlib/v1.7/TOML/src/print.jl:171
 [6] top-level scope
   @ REPL[7]:1
@KristofferC KristofferC added bug Indicates an unexpected problem or unintended behavior TOML labels May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior TOML
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants