Skip to content

Multiline string marshalling creates unneccesary escapes #990

@0xf0xx0

Description

@0xf0xx0

Describe the bug
When marshalling a multiline string, go-toml/v2 escapes quotes that don't need to be.

To Reproduce

type Foo struct {
	Foo string `toml:"foo,multiline"`
}
s := Foo{
	Foo: "bar\n\"baz\"\n\"bam\n",
}
enc, _ := toml.Marshal(s)
println(string(enc))

The output is:

foo = """
bar
\"baz\"
\"bam
"""

Expected behavior
I expected the output to be

foo = """
bar
"baz"
"bam
"""

Versions

  • go-toml: v2.2.4
  • go: 1.24.3
  • operating system: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions