Skip to content

Commit 8b72c09

Browse files
paldayararslan
authored andcommitted
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]> (cherry picked from commit e732706)
1 parent 6ee9546 commit 8b72c09

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
@@ -97,9 +97,10 @@ function printvalue(f::MbyFunc, io::IO, value::TOMLValue)
9797
value isa AbstractFloat ? Base.print(io, isnan(value) ? "nan" :
9898
isinf(value) ? string(value > 0 ? "+" : "-", "inf") :
9999
Float64(value)) : # TOML specifies IEEE 754 binary64 for float
100-
value isa AbstractString ? (Base.print(io, "\"");
100+
value isa AbstractString ? (qmark = Base.contains(value, "\n") ? "\"\"\"" : "\"";
101+
Base.print(io, qmark);
101102
print_toml_escaped(io, value);
102-
Base.print(io, "\"")) :
103+
Base.print(io, qmark)) :
103104
value isa AbstractDict ? print_inline_table(f, io, value) :
104105
error("internal error in TOML printing, unhandled value")
105106
end

stdlib/TOML/test/print.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,13 @@ d = "hello"
140140
a = 2
141141
b = 9.9
142142
"""
143+
144+
# multiline strings (#55083)
145+
s = """
146+
a = \"\"\"lorem ipsum
147+
148+
149+
150+
alpha\"\"\"
151+
"""
152+
@test roundtrip(s)

0 commit comments

Comments
 (0)