From 78c1871a82e58da8d90b497d113bb766695783bd Mon Sep 17 00:00:00 2001 From: Andrew-M-C Date: Tue, 7 May 2024 20:40:44 +0800 Subject: [PATCH] [*] fix: Issue #30 --- .github/workflows/go_1.16_before.yml | 4 +- jsonvalue.go | 2 + marshal_test.go | 55 ++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go_1.16_before.yml b/.github/workflows/go_1.16_before.yml index f60de8e..ddc7732 100644 --- a/.github/workflows/go_1.16_before.yml +++ b/.github/workflows/go_1.16_before.yml @@ -9,7 +9,7 @@ on: env: CODECOV_TOKEN: '2fc0d617-8e9a-47d7-ab58-52fa92b23741' - MAIN_GO_VER: '1.16' + MAIN_GO_VER: '1.13' MAIN_HOST_OS: 'ubuntu-latest' jobs: @@ -18,7 +18,7 @@ jobs: max-parallel: 6 matrix: GO_VER: ['1.13', '1.14', '1.15'] - HOST_OS: ['ubuntu-latest', 'macos-latest'] + HOST_OS: ['ubuntu-latest'] runs-on: ${{ matrix.HOST_OS }} diff --git a/jsonvalue.go b/jsonvalue.go index 6c71493..73247bb 100644 --- a/jsonvalue.go +++ b/jsonvalue.go @@ -518,6 +518,8 @@ func (v *V) deepCopy() *V { res := new(globalPool{}, Array) res.children = v.children.deepCopy() return res + case Boolean: + return NewBool(v.Bool()) case Null: return NewNull() } diff --git a/marshal_test.go b/marshal_test.go index 88ed0b8..08b0360 100644 --- a/marshal_test.go +++ b/marshal_test.go @@ -18,6 +18,7 @@ func testMarshal(t *testing.T) { cv("indent", func() { testMarshalIndent(t) }) cv("ASCII control characters", func() { testMarshalControlCharacters(t) }) cv("test JSONP and control ASCII for UTF-8", func() { testMarshalJSONPAndControlAsciiForUTF8(t) }) + cv("Issue #30", func() { testIssue30(t) }) } func testMarshalFloat64NaN(*testing.T) { @@ -605,3 +606,57 @@ func testMarshalJSONPAndControlAsciiForUTF8(t *testing.T) { so(err, isNil) so(v.String(), eq, string(unshownableControlCharsAndJSONPSpecial)) } + +func testIssue30(t *testing.T) { + cv("Issue #30", func() { + responseData, err := MustUnmarshalString(issue30Raw).Get("data") + so(err, isNil) + + var candidateInfoArr []*V + candidateInfoArr = append(candidateInfoArr, responseData.ForRangeArr()...) + data := candidateInfoArr + + v := NewObject() + v.MustSet(data).At("data") + + b := v.MustMarshal(OptSetSequence()) + t.Log(v) + t.Log(string(b)) + + var m json.RawMessage + err = json.Unmarshal(b, &m) + so(err, isNil) + }) + + cv("stripped Issue #30", func() { + list := []*V{ + NewObject(map[string]any{"archived": false}), + NewObject(map[string]any{"archived": false}), + } + + v, err := Import(list) + so(err, isNil) + so(v.IsArray(), isTrue) + + t.Log(v) + }) +} + +const issue30Raw = `{ + "data": [ + { + "basicInfo": { + "num": 0, + "str": "", + "archived": true + } + }, + { + "basicInfo": { + "num": 1, + "str": "", + "archived": false + } + } + ] +}`