Revert "utils: do not raise on Django syntax error in templated_url (#34518)"

This reverts commit be570b5762.

Original commit pushed by accident.
This commit is contained in:
Emmanuel Cazenave 2019-09-25 18:35:28 +02:00
parent be570b5762
commit d0bfc7649e
3 changed files with 3 additions and 12 deletions

View File

@ -55,7 +55,7 @@ def get_templated_url(url, context=None):
except VariableDoesNotExist as e:
raise TemplateError(e.msg, e.params)
except TemplateSyntaxError:
return 'TEMPLATE ERROR'
raise TemplateError('syntax error')
# ezt-like template
def repl(matchobj):
varname = matchobj.group(0)[1:-1]

View File

@ -296,13 +296,3 @@ def test_render(app):
response = app.get(page.get_online_url())
assert '<meta name="description" content="page description" />' 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

View File

@ -131,7 +131,8 @@ def test_templated_url():
assert get_templated_url('{{ foo.0.bar }}{{ foo.0.zoo }}', context={'foo': [{'bar': 'ok'}, 'ko']}) == 'ok'
# catch django syntax errors in TemplateError
for template in ('{% foobar %}', '{% if "coucou" %}', '{{}}', '{{ if "x" }}', '{{ _private }}'):
assert get_templated_url(template, context=ctx) == 'TEMPLATE ERROR'
with pytest.raises(TemplateError, match='syntax error'):
assert get_templated_url(template, context=ctx) == 'bar'
# requestcontext
with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net'}):