Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use triple quotes in TOML.print when string contains newline #55084

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions stdlib/TOML/src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -195,3 +195,13 @@ LocalPkg = {path = "LocalPkg"}
"""
@test toml_str(d; sorted=true, inline_tables) == s
@test roundtrip(s)

# multiline strings (#55083)
s = """
a = \"\"\"lorem ipsum



alpha\"\"\"
"""
@test roundtrip(s)