Skip to content

Commit

Permalink
Use triple quotes in TOML.print when string contains newline (#55084)
Browse files Browse the repository at this point in the history
closes #55083

Shouldu this also check for `\r`?

---------

Co-authored-by: Alex Arslan <ararslan@comcast.net>
(cherry picked from commit e732706)
  • Loading branch information
palday authored and KristofferC committed Jul 24, 2024
1 parent 6ee9546 commit 8b72c09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stdlib/TOML/src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions stdlib/TOML/test/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,13 @@ d = "hello"
a = 2
b = 9.9
"""

# multiline strings (#55083)
s = """
a = \"\"\"lorem ipsum
alpha\"\"\"
"""
@test roundtrip(s)

0 comments on commit 8b72c09

Please sign in to comment.