0001-misc-don-t-crash-templates-on-variables-with-invalid.patch
tests/test_templates.py | ||
---|---|---|
108 | 108 |
tmpl = Template('{{ plop|parse_time|date:"H i" }}') |
109 | 109 |
assert tmpl.render({'plop': '10:32'}) == '10 32' |
110 | 110 |
assert tmpl.render({'plop': 'x'}) == '' |
111 | ||
112 |
def test_variable_unicode_error_handling(): |
|
113 |
tmpl = Template('{{ form_var_éléphant }}') |
|
114 |
assert tmpl.render() == '' |
wcs/qommon/template.py | ||
---|---|---|
523 | 523 |
variable_resolve_orig = django.template.base.Variable.resolve |
524 | 524 | |
525 | 525 |
def variable_resolve(self, context): |
526 |
value = variable_resolve_orig(self, context) |
|
526 |
try: |
|
527 |
value = variable_resolve_orig(self, context) |
|
528 |
except UnicodeEncodeError: |
|
529 |
return context.template.engine.string_if_invalid |
|
527 | 530 |
if isinstance(value, SafeString): |
528 | 531 |
return SafeUnicode(value, 'utf-8') |
529 | 532 |
if isinstance(value, str): |
530 |
- |