mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Fixed lexer in decoding base64-encoded []byte field with forward slash in it. (#328)
Co-authored-by: Maksim Kochkin <maksim.kochkin@magiclab.co>
This commit is contained in:
co-authored by
Maksim Kochkin
parent
fca00f44f1
commit
a833663add
@@ -712,6 +712,10 @@ func (r *Lexer) Bytes() []byte {
|
||||
r.errInvalidToken("string")
|
||||
return nil
|
||||
}
|
||||
if err := r.unescapeStringToken(); err != nil {
|
||||
r.errInvalidToken("string")
|
||||
return nil
|
||||
}
|
||||
ret := make([]byte, base64.StdEncoding.DecodedLen(len(r.token.byteValue)))
|
||||
n, err := base64.StdEncoding.Decode(ret, r.token.byteValue)
|
||||
if err != nil {
|
||||
|
||||
@@ -89,6 +89,7 @@ func TestBytes(t *testing.T) {
|
||||
}{
|
||||
{toParse: `"c2ltcGxlIHN0cmluZw=="`, want: "simple string"},
|
||||
{toParse: " \r\r\n\t " + `"dGVzdA=="`, want: "test"},
|
||||
{toParse: `"c3ViamVjdHM\/X2Q9MQ=="`, want: "subjects?_d=1"}, // base64 with forward slash escaped
|
||||
|
||||
{toParse: `5`, wantError: true}, // not a JSON string
|
||||
{toParse: `"foobar"`, wantError: true}, // not base64 encoded
|
||||
|
||||
Reference in New Issue
Block a user