Skip to content

Commit

Permalink
json: trim payload before checking it
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrlsnchs committed Oct 25, 2019
1 parent bfe57f3 commit cde46db
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion json.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package jwt

import "errors"
import (
"bytes"
"errors"
)

// ErrNotJSONObject is the error for when a JWT payload is not a JSON object.
var ErrNotJSONObject = errors.New("jwt: payload is not a valid JSON object")

func isJSONObject(payload []byte) bool {
payload = bytes.TrimSpace(payload)
return payload[0] == '{' && payload[len(payload)-1] == '}'
}

0 comments on commit cde46db

Please sign in to comment.