From 148d67aaa52ce0ac667ca037bdd445b0e634b52f Mon Sep 17 00:00:00 2001 From: redryerye Date: Thu, 5 Dec 2019 19:41:58 +0900 Subject: [PATCH] Add guard to handle index out of range exception --- Sources/SwiftJWT/JWTDecoder.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftJWT/JWTDecoder.swift b/Sources/SwiftJWT/JWTDecoder.swift index 40350f3..d855204 100644 --- a/Sources/SwiftJWT/JWTDecoder.swift +++ b/Sources/SwiftJWT/JWTDecoder.swift @@ -75,7 +75,8 @@ public class JWTDecoder: BodyDecoder { public func decode(_ 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