fix(tokeniser): Tokenising a quote inside quoted parameter (#210)
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
# Stencil Changelog
|
# Stencil Changelog
|
||||||
|
|
||||||
|
## Master
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Fixed using quote as a filter parameter
|
||||||
|
|
||||||
|
|
||||||
## 0.11.0 (2018-04-04)
|
## 0.11.0 (2018-04-04)
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ extension String {
|
|||||||
|
|
||||||
if separate != separator {
|
if separate != separator {
|
||||||
word.append(separate)
|
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)
|
components.append(word)
|
||||||
word = ""
|
word = ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,16 @@ func testFilterTag() {
|
|||||||
let result = try env.renderTemplate(string: "{% filter split:\",\"|join:\";\" %}{{ items|join:\",\" }}{% endfilter %}", context: ["items": [1, 2]])
|
let result = try env.renderTemplate(string: "{% filter split:\",\"|join:\";\" %}{{ items|join:\",\" }}{% endfilter %}", context: ["items": [1, 2]])
|
||||||
try expect(result) == "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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user