Skip to content

TOML: Dict inside mixed vector produces invalid TOML #45340

Closed
@fonsp

Description

@fonsp
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    TOMLbugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions