Projet

Général

Profil

0002-misc-use-absolute-URIs-for-links-in-text-cell-in-ske.patch

Frédéric Péters, 05 mai 2019 13:15

Télécharger (2,11 ko)

Voir les différences:

Subject: [PATCH 2/2] 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(+)
combo/data/models.py
751 751
            def sub_src(match):
752 752
                url = request.build_absolute_uri(match.group(1))
753 753
                return 'src="%s"' % url
754
            def sub_href(match):
755
                url = match.group(1)
756
                if url.startswith('#'):
757
                    pass
758
                else:
759
                    url = request.build_absolute_uri(url)
760
                return 'href="%s"' % url
754 761
            extra_context['text'] = re.sub(r'src="(.*?)"', sub_src, self.text)
762
            extra_context['text'] = re.sub(r'href="(.*?)"', sub_href, extra_context['text'])
755 763
        return extra_context
756 764

  
757 765

  
tests/test_public.py
285 285
    # check absolute URIs are not modified
286 286
    assert 'src="http://www.example.com/test.png"' in resp.text
287 287

  
288
    # check links in text cell use full URL
289
    cell.text = '''<a href="/test/foobar"> vs
290
                   <a href="http://www.example.com/test"> vs'
291
                   <a href="#top">'''
292
    cell.save()
293
    resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/'))
294
    assert 'href="http://testserver/test/foobar"' in resp.text
295
    assert 'href="http://www.example.com/test"' in resp.text
296
    assert 'href="#top"' in resp.text
297

  
288 298
    # add a bad redirection page (don't use it, do not crash)
289 299
    page = Page(title='BadRedirection', slug='badredir', template_name='standard',
290 300
            redirect_url='[foo_bar]')
291
-