Skip to content

Commit 4a5c27c

Browse files
authored
decode: fix wrong indention for tables' comments (#892)
1 parent 76cc96f commit 4a5c27c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

marshaler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,12 +983,12 @@ func (enc *Encoder) encodeSliceAsArrayTable(b []byte, ctx encoderCtx, v reflect.
983983
scratch = append(scratch, "]]\n"...)
984984
ctx.skipTableHeader = true
985985

986+
b = enc.encodeComment(ctx.indent, ctx.options.comment, b)
987+
986988
if enc.indentTables {
987989
ctx.indent++
988990
}
989991

990-
b = enc.encodeComment(ctx.indent, ctx.options.comment, b)
991-
992992
for i := 0; i < v.Len(); i++ {
993993
if i != 0 {
994994
b = append(b, "\n"...)

marshaler_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ func TestMarhsalIssue888(t *testing.T) {
12081208
}
12091209

12101210
type Cfg struct {
1211-
Custom []Thing
1211+
Custom []Thing `comment:"custom config"`
12121212
}
12131213

12141214
buf := new(bytes.Buffer)
@@ -1223,7 +1223,8 @@ func TestMarhsalIssue888(t *testing.T) {
12231223
encoder := toml.NewEncoder(buf).SetIndentTables(true)
12241224
encoder.Encode(config)
12251225

1226-
expected := `[[Custom]]
1226+
expected := `# custom config
1227+
[[Custom]]
12271228
# my field A
12281229
FieldA = 'field a 1'
12291230
# my field B

0 commit comments

Comments
 (0)