@@ -1,5 +1,13 @@
|
|||||||
# Stencil Changelog
|
# Stencil Changelog
|
||||||
|
|
||||||
|
## Master
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Fixes a potential crash when using the `{% for %}` template tag with the
|
||||||
|
incorrect amount of arguments.
|
||||||
|
|
||||||
|
|
||||||
## 0.9.0
|
## 0.9.0
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class ForNode : NodeType {
|
|||||||
class func parse(_ parser:TokenParser, token:Token) throws -> NodeType {
|
class func parse(_ parser:TokenParser, token:Token) throws -> NodeType {
|
||||||
let components = token.components()
|
let components = token.components()
|
||||||
|
|
||||||
guard components.count >= 2 && components[2] == "in" &&
|
guard components.count >= 3 && components[2] == "in" &&
|
||||||
(components.count == 4 || (components.count >= 6 && components[4] == "where")) else {
|
(components.count == 4 || (components.count >= 6 && components[4] == "where")) else {
|
||||||
throw TemplateSyntaxError("'for' statements should use the following 'for x in y where condition' `\(token.contents)`.")
|
throw TemplateSyntaxError("'for' statements should use the following 'for x in y where condition' `\(token.contents)`.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,6 +134,15 @@ func testForNode() {
|
|||||||
let node = ForNode(resolvable: Variable("dict"), loopVariables: ["key", "value"], nodes: nodes, emptyNodes: emptyNodes, where: nil)
|
let node = ForNode(resolvable: Variable("dict"), loopVariables: ["key", "value"], nodes: nodes, emptyNodes: emptyNodes, where: nil)
|
||||||
try expect(try node.render(context)) == "oneItwoII"
|
try expect(try node.render(context)) == "oneItwoII"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$0.it("handles invalid input") {
|
||||||
|
let tokens: [Token] = [
|
||||||
|
.block(value: "for i"),
|
||||||
|
]
|
||||||
|
let parser = TokenParser(tokens: tokens, environment: Environment())
|
||||||
|
let error = TemplateSyntaxError("'for' statements should use the following 'for x in y where condition' `for i`.")
|
||||||
|
try expect(try parser.parse()).toThrow(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user