Skip to content

Commit

Permalink
- Fix display of ZMI breadcrumbs with non-ASCII path elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Feb 3, 2019
1 parent 4dc1700 commit 9024faf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ https://github.com/zopefoundation/Zope/blob/4.0a6/CHANGES.rst
Fixes
+++++

- Fix display of ZMI breadcrumbs with non-ASCII path elements
(`#401 <https://github.com/zopefoundation/Zope/issues/401>`_)

- Fix configuring the maximum number of conflict retries
(`#413 <https://github.com/zopefoundation/Zope/issues/413>`_)

Expand Down
11 changes: 9 additions & 2 deletions src/App/Management.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ExtensionClass import Base
from six.moves.urllib.parse import quote, unquote
from zExceptions import Redirect
from ZPublisher.HTTPRequest import default_encoding
from zope.interface import implementer
import itertools
import six
Expand Down Expand Up @@ -100,13 +101,19 @@ def tabs_path_default(self, REQUEST):
return
last = steps.pop()
for step in steps:
title = escape(unquote(step))
if isinstance(title, bytes):
title = title.decode(default_encoding)
script = '%s/%s' % (script, step)
yield {'url': linkpat.format(escape(script, True)),
'title': escape(unquote(step)),
'title': title,
'last': False}
script = '%s/%s' % (script, last)
title = escape(unquote(last))
if isinstance(title, bytes):
title = title.decode(default_encoding)
yield {'url': linkpat.format(escape(script, True)),
'title': escape(unquote(last)),
'title': title,
'last': True}

def tabs_path_info(self, script, path):
Expand Down
47 changes: 47 additions & 0 deletions src/App/tests/testManagement.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import os.path
import six
from six.moves.urllib.parse import unquote

from Acquisition import aq_base
import Testing.ZopeTestCase


Expand Down Expand Up @@ -41,3 +46,45 @@ def test_Management__Navigation__manage_page_header__5(self):
self.folder.manage_addProperty(
'zmi_additional_css_paths', '', 'string')
self.assertNotIn('href=""', self.folder.manage_page_header())


class TestTabs(Testing.ZopeTestCase.ZopeTestCase):

def afterSetUp(self):
super(TestTabs, self).afterSetUp()
# Need to set PARENTS on the request, needed by REQUEST.traverse
self.request = self.app.REQUEST
self.request.other.update({'PARENTS': [self.app]})

def _makeOne(self):
from App.Management import Tabs
return Tabs()

def test_tabs_path_default_nonascii(self):
""" Test manage_tabs breadcrumbs info with non-ASCII IDs
"""
from OFS.Image import manage_addFile
u_test_id = u'\xe4\xf6\xfc'
if six.PY2:
test_id = u_test_id.encode('UTF-8')
else:
test_id = u_test_id

manage_addFile(self.folder, test_id)
test_file = self.folder._getOb(test_id)
test_file_path = '/%s/%s' % (self.folder.getId(), test_file.getId())
tabs = self._makeOne()

# Set up the request by traversing to the test file
self.request.traverse(test_file_path)
tab_info = list(tabs.tabs_path_default(self.request))
test_tab = tab_info[-1] # The last element is the test file

self.assertTrue(test_tab['last'])
self.assertEqual(test_tab['title'], u_test_id)
tab_path = unquote(test_tab['url'])
self.assertEqual(tab_path, '%s/manage_workspace' % test_file_path)

# See if what we get from the path is really what we want
grabbed = self.app.unrestrictedTraverse(os.path.dirname(tab_path))
self.assertTrue(aq_base(test_file) is aq_base(grabbed))

0 comments on commit 9024faf

Please sign in to comment.