Skip to content

Commit

Permalink
Fixed lexer in decoding base64-encoded []byte field with forward slas…
Browse files Browse the repository at this point in the history
…h in it. (#328)

Co-authored-by: Maksim Kochkin <[email protected]>
  • Loading branch information
ksimka and Maksim Kochkin authored Feb 6, 2021
1 parent fca00f4 commit a833663
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jlexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions jlexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a833663

Please sign in to comment.