Skip to content

Commit

Permalink
Merge pull request #29 from lksnmnn/fix-utf8-encoding
Browse files Browse the repository at this point in the history
fix(renderer): allow unicode for no-escape variables
  • Loading branch information
noahmorrison authored Jun 16, 2018
2 parents 8dbc2cb + 87099af commit 61e2d5a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion chevron/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
# If we're a no html escape tag
elif tag == 'no escape':
# Just lookup the key and add it
output += str(_get_key(key, scopes))
thing = _get_key(key, scopes)
if type(thing) != unicode:
thing = unicode(str(thing), 'utf-8')
output += thing

# If we're a section tag
elif tag == 'section':
Expand Down
3 changes: 2 additions & 1 deletion tests/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"scope": {
"test": "new test"
},
"unicode": "(╯°□°)╯︵ ┻━┻"
"unicode": "(╯°□°)╯︵ ┻━┻",
"unicode_html": "<a>(╯°□°)╯︵ ┻━┻"
}
7 changes: 7 additions & 0 deletions tests/test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,10 @@ unicode test (partial)
===
(╯°□°)╯︵ ┻━┻
===

unicode test (no-escape)
===
{{& unicode_html }}
===
<a>(╯°□°)╯︵ ┻━┻
===
7 changes: 7 additions & 0 deletions tests/test.rendered
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,10 @@ unicode test (partial)
===
(╯°□°)╯︵ ┻━┻
===

unicode test (no-escape)
===
<a>(╯°□°)╯︵ ┻━┻
===
<a>(╯°□°)╯︵ ┻━┻
===

0 comments on commit 61e2d5a

Please sign in to comment.