Stop context stack climbing with "." prefix

This commit is contained in:
Adam Fowler
2021-03-24 11:12:38 +00:00
parent f7bd02267e
commit 7ebd84a328
2 changed files with 16 additions and 1 deletions

View File

@@ -99,6 +99,16 @@ final class TemplateRendererTests: XCTestCase {
XCTAssertEqual(template2.render("<>"), "&lt;&gt;")
}
func testStopClimbingStack() throws {
let template1 = try HBMustacheTemplate(string: "{{#test}}{{name}}{{/test}}")
let template2 = try HBMustacheTemplate(string: "{{#test}}{{.name}}{{/test}}")
let object: [String: Any] = ["test": [:], "name": "John"]
let object2: [String: Any] = ["test": ["name": "Jane"], "name": "John"]
XCTAssertEqual(template1.render(object), "John")
XCTAssertEqual(template2.render(object), "")
XCTAssertEqual(template2.render(object2), "Jane")
}
/// variables
func testMustacheManualExample1() throws {
let template = try HBMustacheTemplate(string: """