Skip to content

Commit

Permalink
Merge pull request #110 from plone/thet-fix103
Browse files Browse the repository at this point in the history
Fix get_top_site_from_url, Issue #103.
  • Loading branch information
thet authored Oct 7, 2016
2 parents 7e36636 + 8eb204b commit ac1275f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ New features:

Bug fixes:

- *add item here*
- Fix issue with ``get_top_site_from_url``, where in some circumstances a ValueError was thrown.
If that happens, just return ``getSite``.
You will only notice, if you have subsites, access them non-VirtualHost-rooted and an error is thrown.
Then folder contents won't be able to navigate up to the root Plone site.
[thet]


3.3.1 (2016-09-23)
Expand Down
17 changes: 11 additions & 6 deletions plone/app/content/browser/contents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ def get_top_site_from_url(context, request):
url_path = urlparse(context.absolute_url()).path.split('/')

site = getSite()
for idx in range(len(url_path)):
_path = '/'.join(url_path[:idx + 1]) or '/'
site_path = request.physicalPathFromURL(_path)
site = context.restrictedTraverse('/'.join(site_path) or '/')
if ISite.providedBy(site):
break
try:
for idx in range(len(url_path)):
_path = '/'.join(url_path[:idx + 1]) or '/'
site_path = request.physicalPathFromURL(_path)
site = context.restrictedTraverse('/'.join(site_path) or '/')
if ISite.providedBy(site):
break
except ValueError:
# Refs: https://github.com/plone/plone.app.content/issues/103
# On error, just return getSite.
return getSite()
return site


Expand Down

0 comments on commit ac1275f

Please sign in to comment.