Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a fallback uint8 sliceDecoder to bytesDecoder #361

Merged
merged 4 commits into from Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Expand Up @@ -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
8 changes: 8 additions & 0 deletions .golangci.yml
Expand Up @@ -48,6 +48,14 @@ linters:
- nlreturn
- testpackage
- wsl
- varnamelen
- nilnil
- ireturn
- govet
- forcetypeassert
- cyclop
- containedctx
- revive

issues:
exclude-rules:
Expand Down
11 changes: 11 additions & 0 deletions decode_test.go
Expand Up @@ -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)
}
}
5 changes: 2 additions & 3 deletions internal/decoder/bytes.go
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions internal/decoder/compile_norace.go
@@ -1,3 +1,4 @@
//go:build !race
// +build !race

package decoder
Expand Down
1 change: 1 addition & 0 deletions internal/decoder/compile_race.go
@@ -1,3 +1,4 @@
//go:build race
// +build race

package decoder
Expand Down