mirror of
https://github.com/go-ini/ini.git
synced 2026-06-19 21:46:45 +02:00
file: fix whitespaces are filtered in the SaveTo method (#260)
This commit is contained in:
@@ -454,6 +454,8 @@ func (f *File) writeToBuffer(indent string) (*bytes.Buffer, error) {
|
||||
val = `"""` + val + `"""`
|
||||
} else if !f.options.IgnoreInlineComment && strings.ContainsAny(val, "#;") {
|
||||
val = "`" + val + "`"
|
||||
} else if len(strings.TrimSpace(val)) != len(val) {
|
||||
val = `"` + val + `"`
|
||||
}
|
||||
if _, err := buf.WriteString(equalSign + val + LineBreak); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -437,6 +437,25 @@ test =
|
||||
`)
|
||||
|
||||
})
|
||||
|
||||
Convey("Keep leading and trailing spaces in value", t, func() {
|
||||
f, _ := ini.Load([]byte(`[foo]
|
||||
bar1 = ' val ue1 '
|
||||
bar2 = """ val ue2 """
|
||||
bar3 = " val ue3 "
|
||||
`))
|
||||
So(f, ShouldNotBeNil)
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err := f.WriteTo(&buf)
|
||||
So(err, ShouldBeNil)
|
||||
So(buf.String(),ShouldEqual,`[foo]
|
||||
bar1 = " val ue1 "
|
||||
bar2 = " val ue2 "
|
||||
bar3 = " val ue3 "
|
||||
|
||||
`)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFile_SaveTo(t *testing.T) {
|
||||
|
||||
Vendored
+1
-1
@@ -84,5 +84,5 @@ true = 2+3=5
|
||||
ADDRESS = """404 road,
|
||||
NotFound, State, 50000"""
|
||||
two_lines = how about continuation lines?
|
||||
lots_of_lines = 1 2 3 4
|
||||
lots_of_lines = "1 2 3 4 "
|
||||
|
||||
|
||||
Reference in New Issue
Block a user