fix(tokeniser): Tokenising a quote inside quoted parameter (#210)

This commit is contained in:
Ilya Puchka
2018-04-17 19:28:28 +01:00
committed by Kyle Fuller
parent 88e54ab4ba
commit 7c499cc077
3 changed files with 19 additions and 1 deletions

View File

@@ -1,5 +1,12 @@
# Stencil Changelog
## Master
### Bug Fixes
- Fixed using quote as a filter parameter
## 0.11.0 (2018-04-04)
### Enhancements

View File

@@ -18,7 +18,7 @@ extension String {
if separate != separator {
word.append(separate)
} else if singleQuoteCount % 2 == 0 && doubleQuoteCount % 2 == 0 && !word.isEmpty {
} else if (singleQuoteCount % 2 == 0 || doubleQuoteCount % 2 == 0) && !word.isEmpty {
components.append(word)
word = ""
}

View File

@@ -30,5 +30,16 @@ func testFilterTag() {
let result = try env.renderTemplate(string: "{% filter split:\",\"|join:\";\" %}{{ items|join:\",\" }}{% endfilter %}", context: ["items": [1, 2]])
try expect(result) == "1;2"
}
$0.it("can render filters with quote as an argument") {
let ext = Extension()
ext.registerFilter("replace", filter: {
print($1[0] as! String)
return ($0 as! String).replacingOccurrences(of: $1[0] as! String, with: $1[1] as! String)
})
let env = Environment(extensions: [ext])
let result = try env.renderTemplate(string: "{% filter replace:'\"',\"\" %}{{ items|join:\",\" }}{% endfilter %}", context: ["items": ["\"1\"", "\"2\""]])
try expect(result) == "1,2"
}
}
}