@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
- Fixes a potential crash when using the `{% for %}` template tag with the
|
- Fixes a potential crash when using the `{% for %}` template tag with the
|
||||||
incorrect amount of arguments.
|
incorrect amount of arguments.
|
||||||
|
- Fixes a potential crash when using incomplete tokens in a template for
|
||||||
|
example, `{%%}` or `{{}}`.
|
||||||
|
|
||||||
|
|
||||||
## 0.9.0
|
## 0.9.0
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ struct Lexer {
|
|||||||
self.templateString = templateString
|
self.templateString = templateString
|
||||||
}
|
}
|
||||||
|
|
||||||
func createToken(string:String) -> Token {
|
func createToken(string: String) -> Token {
|
||||||
func strip() -> String {
|
func strip() -> String {
|
||||||
|
guard string.characters.count > 4 else { return "" }
|
||||||
let start = string.index(string.startIndex, offsetBy: 2)
|
let start = string.index(string.startIndex, offsetBy: 2)
|
||||||
let end = string.index(string.endIndex, offsetBy: -2)
|
let end = string.index(string.endIndex, offsetBy: -2)
|
||||||
return string[start..<end].trim(character: " ")
|
return string[start..<end].trim(character: " ")
|
||||||
|
|||||||
@@ -54,5 +54,15 @@ func testLexer() {
|
|||||||
try expect(tokens[0]) == Token.variable(value: "thing")
|
try expect(tokens[0]) == Token.variable(value: "thing")
|
||||||
try expect(tokens[1]) == Token.variable(value: "name")
|
try expect(tokens[1]) == Token.variable(value: "name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$0.it("can tokenize an unclosed block") {
|
||||||
|
let lexer = Lexer(templateString: "{%}")
|
||||||
|
let _ = lexer.tokenize()
|
||||||
|
}
|
||||||
|
|
||||||
|
$0.it("can tokenize an empty variable") {
|
||||||
|
let lexer = Lexer(templateString: "{{}}")
|
||||||
|
let _ = lexer.tokenize()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user