misc: use absolute URIs for text cell images in skeleton mode (#24681)
This commit is contained in:
parent
25f8065b4c
commit
9727fde513
|
@ -742,6 +742,18 @@ class TextCell(CellBase):
|
|||
d[0]['order'] = -1
|
||||
return d
|
||||
|
||||
def get_cell_extra_context(self, context):
|
||||
extra_context = super(TextCell, self).get_cell_extra_context(context)
|
||||
extra_context['text'] = self.text
|
||||
render_skeleton = context.get('render_skeleton')
|
||||
if render_skeleton:
|
||||
request = context.get('request')
|
||||
def sub_src(match):
|
||||
url = request.build_absolute_uri(match.group(1))
|
||||
return 'src="%s"' % url
|
||||
extra_context['text'] = re.sub(r'src="(.*?)"', sub_src, self.text)
|
||||
return extra_context
|
||||
|
||||
|
||||
@register_cell_class
|
||||
class FortuneCell(CellBase):
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{% block cell-content %}
|
||||
{{cell.text|safe}}
|
||||
{{text|safe}}
|
||||
{% endblock %}
|
||||
|
|
|
@ -275,6 +275,15 @@ def test_page_skeleton(app):
|
|||
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
|
||||
assert 'http://testserver/plop' in resp.text
|
||||
|
||||
# check images in text cell use full URL
|
||||
cell = TextCell(page=page, placeholder='footer', order=0)
|
||||
cell.text = '<img src="/test/foobar.png"> vs <img src="http://www.example.com/test.png">'
|
||||
cell.save()
|
||||
resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
|
||||
assert 'http://testserver/test/foobar.png' in resp.text
|
||||
# check absolute URIs are not modified
|
||||
assert 'src="http://www.example.com/test.png"' 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]')
|
||||
|
|
Loading…
Reference in New Issue