misc: allow verbatim templates in text links in skeleton pages (#65815)

This commit is contained in:
Frédéric Péters 2022-05-31 16:14:51 +02:00
parent d8f7379952
commit 8640f62d31
2 changed files with 16 additions and 7 deletions

View File

@ -1491,7 +1491,10 @@ class TextCell(CellBase):
def sub_href(match):
url = match.group(1)
if url.startswith('#'):
if url.startswith('#') or url.startswith('{'):
# do not make URI of anchor or generated template (this is useful so
# we can get {{registration_url}} exported verbatim in a page to serve
# as custom authentic login page.
pass
else:
url = request.build_absolute_uri(url)

View File

@ -347,15 +347,21 @@ def test_page_skeleton(app):
# check absolute URIs are not modified
assert 'src="http://www.example.com/test.png"' in resp.text
# check links in text cell use full URL
# check links in text cell use full URL (unless anchors and verbatim)
cell.text = '''<a href="/test/foobar"> vs
<a href="http://www.example.com/test"> vs'
<a href="#top">'''
<a href="#top">
<a href="{{ test_url }}">
<a href="{% verbatim %}{{ registration_url }}{% endverbatim %}">
'''
cell.save()
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
assert 'href="http://testserver/test/foobar"' in resp.text
assert 'href="http://www.example.com/test"' in resp.text
assert 'href="#top"' in resp.text
with override_settings(TEMPLATE_VARS={'test_url': 'http://example.net'}):
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
assert 'href="http://testserver/test/foobar"' in resp.text
assert 'href="http://www.example.com/test"' in resp.text
assert 'href="#top"' in resp.text
assert 'href="http://example.net"' in resp.text
assert 'href="{{ registration_url }}"' in resp.text
# add a bad redirection page (don't use it, do not crash)
page = Page(title='BadRedirection', slug='badredir', template_name='standard', redirect_url='[foo_bar]')