diff --git a/stdlib/TOML/src/print.jl b/stdlib/TOML/src/print.jl index 1fa9f97405504..af792b72d2dcc 100644 --- a/stdlib/TOML/src/print.jl +++ b/stdlib/TOML/src/print.jl @@ -97,9 +97,10 @@ function printvalue(f::MbyFunc, io::IO, value::TOMLValue) value isa AbstractFloat ? Base.print(io, isnan(value) ? "nan" : isinf(value) ? string(value > 0 ? "+" : "-", "inf") : Float64(value)) : # TOML specifies IEEE 754 binary64 for float - value isa AbstractString ? (Base.print(io, "\""); + value isa AbstractString ? (qmark = Base.contains(value, "\n") ? "\"\"\"" : "\""; + Base.print(io, qmark); print_toml_escaped(io, value); - Base.print(io, "\"")) : + Base.print(io, qmark)) : value isa AbstractDict ? print_inline_table(f, io, value) : error("internal error in TOML printing, unhandled value") end diff --git a/stdlib/TOML/test/print.jl b/stdlib/TOML/test/print.jl index 765b6feb491a5..d5b325ff9b3b6 100644 --- a/stdlib/TOML/test/print.jl +++ b/stdlib/TOML/test/print.jl @@ -140,3 +140,13 @@ d = "hello" a = 2 b = 9.9 """ + +# multiline strings (#55083) +s = """ +a = \"\"\"lorem ipsum + + + +alpha\"\"\" +""" +@test roundtrip(s)