utils: do not raise on Django syntax error in templated_url (#34518)
This commit is contained in:
parent
0378b9fed5
commit
be570b5762
|
@ -55,7 +55,7 @@ def get_templated_url(url, context=None):
|
||||||
except VariableDoesNotExist as e:
|
except VariableDoesNotExist as e:
|
||||||
raise TemplateError(e.msg, e.params)
|
raise TemplateError(e.msg, e.params)
|
||||||
except TemplateSyntaxError:
|
except TemplateSyntaxError:
|
||||||
raise TemplateError('syntax error')
|
return 'TEMPLATE ERROR'
|
||||||
# ezt-like template
|
# ezt-like template
|
||||||
def repl(matchobj):
|
def repl(matchobj):
|
||||||
varname = matchobj.group(0)[1:-1]
|
varname = matchobj.group(0)[1:-1]
|
||||||
|
|
|
@ -296,3 +296,13 @@ def test_render(app):
|
||||||
response = app.get(page.get_online_url())
|
response = app.get(page.get_online_url())
|
||||||
assert '<meta name="description" content="page description" />' in response.text
|
assert '<meta name="description" content="page description" />' in response.text
|
||||||
assert '<title>Combo - foo</title>' in response.text
|
assert '<title>Combo - foo</title>' in response.text
|
||||||
|
|
||||||
|
def test_render_cell_having_href_template_error(app):
|
||||||
|
page = Page(title=u'foo', slug='foo', template_name='standard-sidebar', order=0, description="page description")
|
||||||
|
page.save()
|
||||||
|
cell = TextCell(page=page,
|
||||||
|
text='<a href="{{e-service_url}}backoffice/...">link</a>',
|
||||||
|
order=0, placeholder='content')
|
||||||
|
cell.save()
|
||||||
|
response = app.get(page.get_online_url())
|
||||||
|
assert '<a href="TEMPLATE ERROR">link</a>' in response.text
|
||||||
|
|
|
@ -131,8 +131,7 @@ def test_templated_url():
|
||||||
assert get_templated_url('{{ foo.0.bar }}{{ foo.0.zoo }}', context={'foo': [{'bar': 'ok'}, 'ko']}) == 'ok'
|
assert get_templated_url('{{ foo.0.bar }}{{ foo.0.zoo }}', context={'foo': [{'bar': 'ok'}, 'ko']}) == 'ok'
|
||||||
# catch django syntax errors in TemplateError
|
# catch django syntax errors in TemplateError
|
||||||
for template in ('{% foobar %}', '{% if "coucou" %}', '{{}}', '{{ if "x" }}', '{{ _private }}'):
|
for template in ('{% foobar %}', '{% if "coucou" %}', '{{}}', '{{ if "x" }}', '{{ _private }}'):
|
||||||
with pytest.raises(TemplateError, match='syntax error'):
|
assert get_templated_url(template, context=ctx) == 'TEMPLATE ERROR'
|
||||||
assert get_templated_url(template, context=ctx) == 'bar'
|
|
||||||
|
|
||||||
# requestcontext
|
# requestcontext
|
||||||
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net'}):
|
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net'}):
|
||||||
|
|
Loading…
Reference in New Issue