diff --git a/file.go b/file.go index ae6264a..9f66426 100644 --- a/file.go +++ b/file.go @@ -305,6 +305,10 @@ func (f *File) writeToBuffer(indent string) (*bytes.Buffer, error) { } else { key.Comment = key.Comment[:1] + " " + strings.TrimSpace(key.Comment[1:]) } + + // Support multiline comments + key.Comment = strings.Replace(key.Comment, "\n", "\n; ", -1) + if _, err := buf.WriteString(key.Comment + LineBreak); err != nil { return nil, err } diff --git a/file_test.go b/file_test.go index 593224b..2a0ca7c 100644 --- a/file_test.go +++ b/file_test.go @@ -264,6 +264,22 @@ func TestFile_WriteTo(t *testing.T) { So(err, ShouldBeNil) So(buf.String(), ShouldEqual, string(expected)) }) + + Convey("Support multiline comments", t, func() { + f := ini.Empty() + f.Section("").Key("test").Comment = "Multiline\nComment" + + var buf bytes.Buffer + _, err := f.WriteTo(&buf) + So(err, ShouldBeNil) + + So(buf.String(), ShouldEqual, `; Multiline +; Comment +test = + +`) + + }) } func TestFile_SaveTo(t *testing.T) { diff --git a/ini.go b/ini.go index 9f6ea3b..4ab4536 100644 --- a/ini.go +++ b/ini.go @@ -32,7 +32,7 @@ const ( // Maximum allowed depth when recursively substituing variable names. _DEPTH_VALUES = 99 - _VERSION = "1.33.0" + _VERSION = "1.34.0" ) // Version returns current package version literal.