Skip to content

Commit

Permalink
fix(tokeniser): Tokenising a quote inside quoted parameter (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyapuchka authored and kylef committed Apr 17, 2018
1 parent 88e54ab commit 7c499cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Stencil Changelog

## Master

### Bug Fixes

- Fixed using quote as a filter parameter


## 0.11.0 (2018-04-04)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
Expand Down
11 changes: 11 additions & 0 deletions Tests/StencilTests/FilterTagSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit 7c499cc

Please sign in to comment.