From d9df77a119f49379052e524092c824f3a07701c7 Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Thu, 7 Apr 2022 18:10:49 +0900 Subject: [PATCH 1/4] fix: add a fallback uint8 sliceDecoder to bytesDecoder fix #360 --- decode_test.go | 11 +++++++++++ internal/decoder/bytes.go | 5 ++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/decode_test.go b/decode_test.go index 57d9c6a4..577d1d52 100644 --- a/decode_test.go +++ b/decode_test.go @@ -3907,3 +3907,14 @@ func TestIssue342(t *testing.T) { t.Errorf("unexpected result: got(%v) != expected(%v)", got, expected) } } + +func TestIssue360(t *testing.T) { + var uints []uint8 + err := json.Unmarshal([]byte(`[0, 1, 2]`), &uints) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if len(uints) != 3 || !(uints[0] == 0 && uints[1] == 1 && uints[2] == 2) { + t.Errorf("unexpected result: %v", uints) + } +} diff --git a/internal/decoder/bytes.go b/internal/decoder/bytes.go index 01a37fef..92c7dcf6 100644 --- a/internal/decoder/bytes.go +++ b/internal/decoder/bytes.go @@ -23,9 +23,8 @@ func byteUnmarshalerSliceDecoder(typ *runtime.Type, structName string, fieldName unmarshalDecoder = newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName) case runtime.PtrTo(typ).Implements(unmarshalTextType): unmarshalDecoder = newUnmarshalTextDecoder(runtime.PtrTo(typ), structName, fieldName) - } - if unmarshalDecoder == nil { - return nil + default: + unmarshalDecoder, _ = compileUint8(typ, structName, fieldName) } return newSliceDecoder(unmarshalDecoder, typ, 1, structName, fieldName) } From 5c2b1916eb29ad33792f412c6d6cf5b3a9a796b1 Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Mon, 11 Apr 2022 18:28:11 +0900 Subject: [PATCH 2/4] chore: update golangci-lint version --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index eb441f7f..684cbc76 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,5 +12,5 @@ jobs: - uses: actions/checkout@v2 - uses: golangci/golangci-lint-action@v2 with: - version: v1.36.0 + version: v1.45.2 args: --timeout=5m From 4311bab3dc77a4f428d80b18d23aa5a04867ac4d Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Mon, 11 Apr 2022 20:43:58 +0900 Subject: [PATCH 3/4] style: go fmt --- internal/decoder/compile_norace.go | 1 + internal/decoder/compile_race.go | 1 + 2 files changed, 2 insertions(+) diff --git a/internal/decoder/compile_norace.go b/internal/decoder/compile_norace.go index 592f6373..eb7e2b13 100644 --- a/internal/decoder/compile_norace.go +++ b/internal/decoder/compile_norace.go @@ -1,3 +1,4 @@ +//go:build !race // +build !race package decoder diff --git a/internal/decoder/compile_race.go b/internal/decoder/compile_race.go index b691bc94..49cdda4a 100644 --- a/internal/decoder/compile_race.go +++ b/internal/decoder/compile_race.go @@ -1,3 +1,4 @@ +//go:build race // +build race package decoder From 0da28e819a8b9597213fc7aa23a55990c4c96ac2 Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Tue, 12 Apr 2022 12:47:36 +0900 Subject: [PATCH 4/4] chore: add disable --- .golangci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 44ae40f6..57ae5a52 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -48,6 +48,14 @@ linters: - nlreturn - testpackage - wsl + - varnamelen + - nilnil + - ireturn + - govet + - forcetypeassert + - cyclop + - containedctx + - revive issues: exclude-rules: