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]')