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 decoding of []byte type #258

Merged
merged 1 commit into from Jun 25, 2021
Merged

Conversation

preethamrn
Copy link
Contributor

This is very similar to the fix here: 8628848

Although the earlier fix applies for Unmarshal, it doesn't fix the case where a user uses NewDecoder(r).Decode(&res)

Here's a sample test that fails

package json

import (
	"bytes"
	"encoding/json"
	"strings"
	"testing"

	goccy "github.com/goccy/go-json"
	"github.com/stretchr/testify/assert"
)

type structure struct {
	InnerBytes []byte `json:"inner_bytes"`
}

func Test_json_decode(t *testing.T) {
	rawData := `{"inner_bytes":"bG93ZXI="}`
	var resNative structure
	var resGoccy structure
	json.NewDecoder(bytes.NewBufferString(rawData)).Decode(&resNative)
	goccy.NewDecoder(bytes.NewBufferString(rawData)).Decode(&resGoccy)
	assert.Equal(t, []byte("lower"), resNative.InnerBytes)
	assert.Equal(t, []byte("lower"), resGoccy.InnerBytes)
}

@codecov-commenter
Copy link

Codecov Report

Merging #258 (2aeb176) into master (397a4e4) will increase coverage by 0.00%.
The diff coverage is 66.66%.

@@           Coverage Diff           @@
##           master     #258   +/-   ##
=======================================
  Coverage   80.97%   80.98%           
=======================================
  Files          47       47           
  Lines       14763    14764    +1     
=======================================
+ Hits        11955    11956    +1     
  Misses       2255     2255           
  Partials      553      553           

@goccy
Copy link
Owner

goccy commented Jun 25, 2021

Thank you for the great PR ! LGTM !

@goccy goccy merged commit 923c0f7 into goccy:master Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants