Skip to content

Commit

Permalink
Add guard to handle index out of range exception (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
redryerye authored and ianpartridge committed Dec 5, 2019
1 parent d4993d2 commit 0d43542
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/SwiftJWT/JWTDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public class JWTDecoder: BodyDecoder {
public func decode<T : Decodable>(_ type: T.Type, fromString: String) throws -> T {
// Seperate the JWT into the headers and claims.
let components = fromString.components(separatedBy: ".")
guard let headerData = JWTDecoder.data(base64urlEncoded: components[0]),
guard components.count > 1,
let headerData = JWTDecoder.data(base64urlEncoded: components[0]),
let claimsData = JWTDecoder.data(base64urlEncoded: components[1])
else {
throw JWTError.invalidJWTString
Expand Down

0 comments on commit 0d43542

Please sign in to comment.