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

Multiline comments missing comment characters #768

Closed
fho opened this issue May 3, 2022 · 3 comments · Fixed by #775
Closed

Multiline comments missing comment characters #768

fho opened this issue May 3, 2022 · 3 comments · Fixed by #775
Labels
bug Issues describing a bug in go-toml.

Comments

@fho
Copy link

fho commented May 3, 2022

Describe the bug
When the comment tag of a struct that is marshalled contains newline characters (\n), it is encoded into an invalid TOML document.
In the encoded version only the first line of the comment starts with the comment character (#).
All other lines of the comments are missing it.

Using \n in comment tags generated valid multiline comments in v1.

How To Reproduce

package main

import (
	"fmt"

	"github.com/pelletier/go-toml/v2"
)

func main() {
	type cfg struct {
		Name string `comment:"This is a multiline comment.\nThis is line 2."`
	}

	out, err := toml.Marshal(&cfg{})
	if err != nil {
		panic(err)
	}

	fmt.Println(string(out))
}

Generated TOML document:

# This is a multiline comment.
This is line 2.
Name = ''

Expected behavior

I expected the following generated TOML document:


# This is a multiline comment.
# This is line 2.
Name = ''

Versions

  • go-toml: v2.0.0
  • go: 1.18.1
  • operating system: Linux
@pelletier
Copy link
Owner

Good catch, thank you for reporting it!

@pelletier pelletier added the bug Issues describing a bug in go-toml. label May 9, 2022
@pelletier pelletier changed the title multiline comments missing comment characters Multiline comments missing comment characters May 10, 2022
pelletier added a commit that referenced this issue May 10, 2022
pelletier added a commit that referenced this issue May 10, 2022
@pelletier
Copy link
Owner

This issue should be fixed with b2e0231. Feel free to re-open if you are still experiencing the issue!

@fho
Copy link
Author

fho commented May 10, 2022

@pelletier thanks a lot! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing a bug in go-toml.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants