diff --git a/encode_test.go b/encode_test.go index 1e1b3c5..54fbddf 100644 --- a/encode_test.go +++ b/encode_test.go @@ -1805,3 +1805,45 @@ func TestIssue104(t *testing.T) { t.Fatalf("expect %q but got %q", string(expect), string(got)) } } + +func TestIssue180(t *testing.T) { + v := struct { + T struct { + T1 bool `json:"t1"` + T2 float64 `json:"t2"` + T3 string `json:"t3"` + T4 []string `json:"t4"` + T5 *struct{} `json:"t5"` + T6 interface{} `json:"t6"` + T7 [][]string `json:"t7"` + } `json:"t"` + }{ + T: struct { + T1 bool `json:"t1"` + T2 float64 `json:"t2"` + T3 string `json:"t3"` + T4 []string `json:"t4"` + T5 *struct{} `json:"t5"` + T6 interface{} `json:"t6"` + T7 [][]string `json:"t7"` + }{ + T4: []string{}, + T7: [][]string{ + []string{""}, + []string{"hello", "world"}, + []string{}, + }, + }, + } + b1, err := stdjson.MarshalIndent(v, "", "\t") + if err != nil { + t.Fatal(err) + } + b2, err := json.MarshalIndent(v, "", "\t") + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(b1, b2) { + t.Fatalf("failed to equal encoded result: expected %s but got %s", string(b1), string(b2)) + } +} diff --git a/internal/encoder/vm_escaped_indent/vm.go b/internal/encoder/vm_escaped_indent/vm.go index b221382..23f2cbf 100644 --- a/internal/encoder/vm_escaped_indent/vm.go +++ b/internal/encoder/vm_escaped_indent/vm.go @@ -338,7 +338,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next store(ctxptr, code.Idx, uintptr(slice.Data)) } else { - b = appendIndent(ctx, b, code.Indent) b = append(b, '[', ']', ',', '\n') code = code.End.Next } @@ -385,7 +384,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next store(ctxptr, code.Idx, p) } else { - b = appendIndent(ctx, b, code.Indent) b = append(b, '[', ']', ',', '\n') code = code.End.Next } diff --git a/internal/encoder/vm_indent/vm.go b/internal/encoder/vm_indent/vm.go index fdad09e..4406462 100644 --- a/internal/encoder/vm_indent/vm.go +++ b/internal/encoder/vm_indent/vm.go @@ -338,7 +338,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next store(ctxptr, code.Idx, uintptr(slice.Data)) } else { - b = appendIndent(ctx, b, code.Indent) b = append(b, '[', ']', ',', '\n') code = code.End.Next } @@ -385,7 +384,6 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet, opt code = code.Next store(ctxptr, code.Idx, p) } else { - b = appendIndent(ctx, b, code.Indent) b = append(b, '[', ']', ',', '\n') code = code.End.Next }