bytedance/sonic

unmarshal UTF8 escaped char with string option is different with encoding/json

Closed

#279 opened on Aug 11, 2022

 (0 comments) (0 reactions) (1 assignee)Go (454 forks)github user discovery
buggood first issueknown-issue

Repository metrics

Stars
 (9,488 stars)
PR merge metrics
 (PR metrics pending)

Description

code:

package issue_test

import (
    `testing`
    . `github.com/bytedance/sonic`
    `encoding/json`

    `github.com/stretchr/testify/require`
)

type StringOptQuote struct { 
    F0 string "json:\"S,string\"" 
}

func TestUnmarshal_StringOption(t *testing.T) {
    var jv, sv StringOptQuote
    data := []byte(`{"S":"\"\u0026\""}`)
    je := json.Unmarshal(data, &jv)
    se := Unmarshal(data, &sv)
    require.Equal(t, je != nil, se != nil)
    require.Equal(t, jv, sv)
}

output:

=== RUN   TestUnmarshal_StringOption
    issuex3_test.go:37: 
                Error Trace:    issuex3_test.go:37
                Error:          Not equal: 
                                expected: false
                                actual  : true
                Test:           TestUnmarshal_StringOption
--- FAIL: TestUnmarshal_StringOption (0.01s)

Contributor guide