Commits

rblank  committed c1a6298

[svn r10872] 0.13dev: Avoid creating URLs with empty segments, as they can't be handled by all web frontends.

Part of #10048.

  • Participants
  • Parent commits 9949e33

Comments (0)

Files changed (2)

File trac/web/href.py

 # Author: Jonas Borgström <jonas@edgewall.com>
 #         Christopher Lenz <cmlenz@gmx.de>
 
+import re
+
 from trac.util.text import unicode_quote, unicode_urlencode
 
 
+slashes_re = re.compile(r'/{2,}')
+
+
 class Href(object):
     """Implements a callable that constructs URLs with the given base. The
     function can be called with any number of positional and keyword
         path = '/'.join(unicode_quote(unicode(arg).strip('/'), self.path_safe)
                         for arg in args if arg is not None)
         if path:
-            href += '/' + path
+            href += '/' + slashes_re.sub('/', path).lstrip('/')
         elif not href:
             href = '/'
 

File trac/web/tests/href.py

         self.assertEqual('/base/sub', href('/sub/'))
         self.assertEqual('/base/sub/other', href('sub', 'other'))
         self.assertEqual('/base/sub/other', href('sub', None, 'other'))
-        self.assertEqual('/base/sub//other', href('sub', '', 'other'))  # ???
+        self.assertEqual('/base/sub/other', href('sub', '', 'other'))
+        self.assertEqual('/base/sub/other', href('sub', '', '', 'other'))
+        self.assertEqual('/base/sub/other', href('', 'sub', 'other'))
+        self.assertEqual('/base/sub/other/', href('sub', 'other', ''))
         self.assertEqual('/base/with%20special%26chars',
                          href('with special&chars'))
         assert href('page', param='value', other='other value', more=None) in [
         self.assertEqual('/sub', href('/sub/'))
         self.assertEqual('/sub/other', href('sub', 'other'))
         self.assertEqual('/sub/other', href('sub', None, 'other'))
-        self.assertEqual('/sub//other', href('sub', '', 'other'))       # ???
+        self.assertEqual('/sub/other', href('sub', '', 'other'))
+        self.assertEqual('/sub/other', href('sub', '', '', 'other'))
+        self.assertEqual('/sub/other', href('', 'sub', 'other'))
+        self.assertEqual('/sub/other/', href('sub', 'other', ''))
         self.assertEqual('/with%20special%26chars',
                          href('with special&chars'))
         assert href('page', param='value', other='other value', more=None) in [