From 0d435423d12e61c0d14adb6d04396c08a6a650f1 Mon Sep 17 00:00:00 2001 From: Yuki Yamamoto Date: Fri, 6 Dec 2019 00:14:54 +0900 Subject: [PATCH] Add guard to handle index out of range exception (#83) --- 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