From 74100d9622463dee536b3e25e6c7abef9a390cb4 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 8 Jul 2024 17:01:01 -0500 Subject: [PATCH 1/4] Use triple quotes in TOML.print when string contains newline --- stdlib/TOML/src/print.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/TOML/src/print.jl b/stdlib/TOML/src/print.jl index 168a7f63c6b5b..84b41fa2ed7fb 100644 --- a/stdlib/TOML/src/print.jl +++ b/stdlib/TOML/src/print.jl @@ -101,9 +101,10 @@ function printvalue(f::MbyFunc, io::IO, value::TOMLValue, sorted::Bool) 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, sorted) : error("internal error in TOML printing, unhandled value") end From 8cbf6f1d7d19283fadd60c4f8f3ac335f48290bc Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Tue, 9 Jul 2024 00:27:12 +0200 Subject: [PATCH 2/4] add test --- stdlib/TOML/test/print.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stdlib/TOML/test/print.jl b/stdlib/TOML/test/print.jl index 79a87b9f0f13f..2341a00765dd2 100644 --- a/stdlib/TOML/test/print.jl +++ b/stdlib/TOML/test/print.jl @@ -195,3 +195,13 @@ LocalPkg = {path = "LocalPkg"} """ @test toml_str(d; sorted=true, inline_tables) == s @test roundtrip(s) + +# multline strings (#55083) +s = """ +a = \"\"\"lorem ipsum + + + +alpha\"\"\" +""" +@test roundtrip(s) From 8cf489c1aafea3da89ebde67aacfcd0be75de303 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 8 Jul 2024 17:27:57 -0500 Subject: [PATCH 3/4] Update stdlib/TOML/src/print.jl Co-authored-by: Alex Arslan --- stdlib/TOML/src/print.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/TOML/src/print.jl b/stdlib/TOML/src/print.jl index 84b41fa2ed7fb..63f65b017d393 100644 --- a/stdlib/TOML/src/print.jl +++ b/stdlib/TOML/src/print.jl @@ -101,7 +101,7 @@ function printvalue(f::MbyFunc, io::IO, value::TOMLValue, sorted::Bool) 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 ? (qmark = Base.contains(value, "\n") ? "\"\"\"" : "\""; + value isa AbstractString ? (qmark = Base.contains(value, "\n") ? "\"\"\"" : "\""; Base.print(io, qmark); print_toml_escaped(io, value); Base.print(io, qmark)) : From ab7306ed8fc765c95e3157db5856061b44ba3134 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Tue, 9 Jul 2024 02:10:56 -0500 Subject: [PATCH 4/4] Update stdlib/TOML/test/print.jl Co-authored-by: Alex Arslan --- stdlib/TOML/test/print.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/TOML/test/print.jl b/stdlib/TOML/test/print.jl index 2341a00765dd2..8fba1b1c1df10 100644 --- a/stdlib/TOML/test/print.jl +++ b/stdlib/TOML/test/print.jl @@ -196,7 +196,7 @@ LocalPkg = {path = "LocalPkg"} @test toml_str(d; sorted=true, inline_tables) == s @test roundtrip(s) -# multline strings (#55083) +# multiline strings (#55083) s = """ a = \"\"\"lorem ipsum