Skip to content

Commit

Permalink
Merge pull request #29 from plone/tg_resolve_host_uids
Browse files Browse the repository at this point in the history
Resolve UIDs with host
  • Loading branch information
jensens authored May 2, 2018
2 parents ae7cc24 + b3d1512 commit 1dfb70a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ New features:

Bug fixes:

- Allow resolving of links with absolute path
- Allow resolving of links with absolute path and host
[tomgross]

- Make plone.namedfile hard testing dependency
Expand Down
12 changes: 8 additions & 4 deletions plone/outputfilters/filters/resolveuid_and_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from six.moves.urllib.parse import unquote
from six.moves.urllib.parse import urljoin
from six.moves.urllib.parse import urlsplit
from six.moves.urllib.parse import urlunsplit
from unidecode import unidecode
from zExceptions import NotFound
from ZODB.POSException import ConflictError
Expand Down Expand Up @@ -332,19 +333,22 @@ def unknown_starttag(self, tag, attrs):
self.in_link = True
if (tag == 'a' or tag == 'area') and 'href' in attributes:
href = attributes['href']
scheme = urlsplit(href)[0]
if not scheme \
and not href.startswith('mailto<') \
url_parts = urlsplit(href)
scheme = url_parts[0]
# we are only interested in path and beyond /foo/bar?x=2#abc
path_parts = urlunsplit(['', ''] + list(url_parts[2:]))
if not href.startswith('mailto<') \
and not href.startswith('mailto:') \
and not href.startswith('tel:') \
and not href.startswith('#'):
obj, subpath, appendix = self.resolve_link(href)
obj, subpath, appendix = self.resolve_link(path_parts)
if obj is not None:
href = obj.absolute_url()
if subpath:
href += '/' + subpath
href += appendix
elif resolveuid_re.match(href) is None \
and not scheme \
and not href.startswith('/'):
# absolutize relative URIs; this text isn't necessarily
# being rendered in the context where it was stored
Expand Down
9 changes: 4 additions & 5 deletions plone/outputfilters/tests/test_resolveuid_and_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ def test_resolve_uids_in_links(self):
<a class="internal-link" href="resolveuid/%s#named-anchor">Some anchored link</a>
</body>
</html>""" % (self.UID, self.UID)
res = self.parser(text)
self.assertTrue('href="http://nohost/plone/image.jpg"' in str(res))
self.assertTrue('href="http://nohost/plone/image.jpg#named-anchor"'
in str(res))
res = str(self.parser(text))
self.assertIn('href="http://nohost/plone/image.jpg"', res)
self.assertIn('href="http://nohost/plone/image.jpg#named-anchor"', res)

def test_resolve_uids_relative_link(self):
text_in = """<a href="../resolveuid/%s">foo</a>""" % self.UID
Expand Down Expand Up @@ -203,7 +202,7 @@ def test_resolve_uids_handles_junk(self):
self._assertTransformsTo(text_in, text_in)

def test_resolve_uids_entities(self):
text_in = """<a class="external-link" href="http://www.example.org/foo?a=1&amp;b=2">example.org</a>"""
text_in = """<a href="http://www.example.org/foo?a=1&amp;b=2" class="external-link">example.org</a>"""
self._assertTransformsTo(text_in, text_in)

def test_resolveuid_view(self):
Expand Down

0 comments on commit 1dfb70a

Please sign in to comment.