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

TOML.print generates invalid TOML on stdout when the values include multiline strings #55083

Closed
palday opened this issue Jul 8, 2024 · 1 comment · Fixed by #55084
Closed
Labels
kind:bug Indicates an unexpected problem or unintended behavior stdlib:TOML stdlib Julia's standard library

Comments

@palday
Copy link
Contributor

palday commented Jul 8, 2024

julia> TOML.print(Dict("a" => """x\nx"""))
a = "x\nx"

julia> TOML.parse("""a = "x\nx" """)
ERROR: TOML Parser error:
none:2:-1 error: newline character in single quoted string
  a = "x
       ^ 
Stacktrace:
 [1] parse
   @ ./toml_parser.jl:445 [inlined]
 [2] parse(str::String)
   @ TOML ~/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/TOML/src/TOML.jl:71
 [3] top-level scope
   @ REPL[99]:1

Interestingly, this seems to only be an issue with stdout and is handled correctly with other IO streams

julia> io = IOBuffer();  TOML.print(io, Dict("a" => """x\nx""")); TOML.parse(seekstart(io))
Dict{String, Any} with 1 entry:
  "a" => "x\nx"

I'm guessing this intersection of two different expectations -- we generally don't include triple quotes for show-type methods going to stdout, but in this particular case, it prevents a simple copy-paste of the generated TOML into other use cases.

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 4 default, 0 interactive, 2 GC (on 4 virtual cores)
@palday palday changed the title TOML.print generates invalid TOML when the values include multiline strings TOML.print generates invalid TOML on stdout when the values include multiline strings Jul 8, 2024
@ararslan ararslan added kind:bug Indicates an unexpected problem or unintended behavior stdlib Julia's standard library stdlib:TOML and removed kind:bug Indicates an unexpected problem or unintended behavior labels Jul 8, 2024
@palday
Copy link
Contributor Author

palday commented Jul 8, 2024

value isa AbstractString ? (Base.print(io, "\"");
print_toml_escaped(io, value);
Base.print(io, "\"")) :

Looks like there's no handling of newlines

@ararslan ararslan added the kind:bug Indicates an unexpected problem or unintended behavior label Jul 8, 2024
KristofferC pushed a commit that referenced this issue Jul 12, 2024
closes #55083

Shouldu this also check for `\r`?

---------

Co-authored-by: Alex Arslan <ararslan@comcast.net>
(cherry picked from commit e732706)
KristofferC pushed a commit that referenced this issue Jul 24, 2024
closes #55083

Shouldu this also check for `\r`?

---------

Co-authored-by: Alex Arslan <ararslan@comcast.net>
(cherry picked from commit e732706)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior stdlib:TOML stdlib Julia's standard library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants