From f80bac14e0c13074ab9110dfc40bd0db48efb20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 5 May 2019 13:13:11 +0200 Subject: [PATCH] misc: use absolute URIs for links in text cell in skeleton mode (#24681) --- combo/data/models.py | 8 ++++++++ tests/test_public.py | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/combo/data/models.py b/combo/data/models.py index 369d9df9..8a57a837 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -751,7 +751,15 @@ class TextCell(CellBase): def sub_src(match): url = request.build_absolute_uri(match.group(1)) return 'src="%s"' % url + def sub_href(match): + url = match.group(1) + if url.startswith('#'): + pass + else: + url = request.build_absolute_uri(url) + return 'href="%s"' % url extra_context['text'] = re.sub(r'src="(.*?)"', sub_src, self.text) + extra_context['text'] = re.sub(r'href="(.*?)"', sub_href, extra_context['text']) return extra_context diff --git a/tests/test_public.py b/tests/test_public.py index d1f31f9c..c93d8b51 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -284,6 +284,16 @@ 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 + cell.text = ''' vs + vs' + ''' + 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 + # 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]')