From 7c499cc077ebc52613f8a94cde39559de23aac2b Mon Sep 17 00:00:00 2001 From: Ilya Puchka Date: Tue, 17 Apr 2018 19:28:28 +0100 Subject: [PATCH] fix(tokeniser): Tokenising a quote inside quoted parameter (#210) --- CHANGELOG.md | 7 +++++++ Sources/Tokenizer.swift | 2 +- Tests/StencilTests/FilterTagSpec.swift | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed61aa5..8bba3744 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Stencil Changelog +## Master + +### Bug Fixes + +- Fixed using quote as a filter parameter + + ## 0.11.0 (2018-04-04) ### Enhancements diff --git a/Sources/Tokenizer.swift b/Sources/Tokenizer.swift index 0e4bf1e9..81680f2d 100644 --- a/Sources/Tokenizer.swift +++ b/Sources/Tokenizer.swift @@ -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 = "" } diff --git a/Tests/StencilTests/FilterTagSpec.swift b/Tests/StencilTests/FilterTagSpec.swift index e2806681..c2864499 100644 --- a/Tests/StencilTests/FilterTagSpec.swift +++ b/Tests/StencilTests/FilterTagSpec.swift @@ -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" + } } }