Skip to content

Commit e732706

Browse files
paldayararslan
andauthored
Use triple quotes in TOML.print when string contains newline (#55084)
closes #55083 Shouldu this also check for `\r`? --------- Co-authored-by: Alex Arslan <[email protected]>
1 parent d7609d8 commit e732706

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

stdlib/TOML/src/print.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ function printvalue(f::MbyFunc, io::IO, value::TOMLValue, sorted::Bool)
101101
value isa AbstractFloat ? Base.print(io, isnan(value) ? "nan" :
102102
isinf(value) ? string(value > 0 ? "+" : "-", "inf") :
103103
Float64(value)) : # TOML specifies IEEE 754 binary64 for float
104-
value isa AbstractString ? (Base.print(io, "\"");
104+
value isa AbstractString ? (qmark = Base.contains(value, "\n") ? "\"\"\"" : "\"";
105+
Base.print(io, qmark);
105106
print_toml_escaped(io, value);
106-
Base.print(io, "\"")) :
107+
Base.print(io, qmark)) :
107108
value isa AbstractDict ? print_inline_table(f, io, value, sorted) :
108109
error("internal error in TOML printing, unhandled value")
109110
end

stdlib/TOML/test/print.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,13 @@ LocalPkg = {path = "LocalPkg"}
195195
"""
196196
@test toml_str(d; sorted=true, inline_tables) == s
197197
@test roundtrip(s)
198+
199+
# multiline strings (#55083)
200+
s = """
201+
a = \"\"\"lorem ipsum
202+
203+
204+
205+
alpha\"\"\"
206+
"""
207+
@test roundtrip(s)

0 commit comments

Comments
 (0)