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:
Maksim Kochkin
2021-02-06 21:55:43 +03:00
committed by GitHub
co-authored by Maksim Kochkin
parent fca00f44f1
commit a833663add
2 changed files with 5 additions and 0 deletions
+4
View File
@@ -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 {
+1
View File
@@ -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