From 482d595d011cc06262a3b6d57827fa973af9ca74 Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Fri, 1 Sep 2017 11:59:52 +0200 Subject: [PATCH] fix(lexer): Handle incomplete tokens Fixes #135 --- CHANGELOG.md | 2 ++ Sources/Lexer.swift | 3 ++- Tests/StencilTests/LexerSpec.swift | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7aac18..5574cce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - Fixes a potential crash when using the `{% for %}` template tag with the incorrect amount of arguments. +- Fixes a potential crash when using incomplete tokens in a template for + example, `{%%}` or `{{}}`. ## 0.9.0 diff --git a/Sources/Lexer.swift b/Sources/Lexer.swift index 8e3fa33..b0ad8f9 100644 --- a/Sources/Lexer.swift +++ b/Sources/Lexer.swift @@ -5,8 +5,9 @@ struct Lexer { self.templateString = templateString } - func createToken(string:String) -> Token { + func createToken(string: String) -> Token { func strip() -> String { + guard string.characters.count > 4 else { return "" } let start = string.index(string.startIndex, offsetBy: 2) let end = string.index(string.endIndex, offsetBy: -2) return string[start..