changeset 495:4284c673bb91

internal: Fix some edge-cases for splitting sub-URIs. A given URI may or may not have a trailing slash, regardless of the `trailing_slash` configuration setting. Add unit tests to check those cases.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 23 Jul 2015 22:11:59 -0700
parents 2537fe95d771
children 95b4e7f9a450
files piecrust/uriutil.py tests/test_uriutil.py
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/uriutil.py	Thu Jul 23 22:09:00 2015 -0700
+++ b/piecrust/uriutil.py	Thu Jul 23 22:11:59 2015 -0700
@@ -92,7 +92,7 @@
     trailing_slash = app.config.get('site/trailing_slash')
     if not pretty_urls:
         uri, ext = os.path.splitext(uri)
-    elif trailing_slash:
+    else:
         uri = uri.rstrip('/')
 
     page_num = 1
--- a/tests/test_uriutil.py	Thu Jul 23 22:09:00 2015 -0700
+++ b/tests/test_uriutil.py	Thu Jul 23 22:11:59 2015 -0700
@@ -30,7 +30,8 @@
     ('/', ('/', 1), True),
     ('/2', ('/', 2), True),
     ('/foo/bar', ('/foo/bar', 1), True),
-    ('/foo/bar/2', ('/foo/bar', 2), True),
+    ('/foo/bar/', ('/foo/bar', 1), True),
+    ('/foo/bar/2/', ('/foo/bar', 2), True),
     ('/foo/bar.ext', ('/foo/bar.ext', 1), True),
     ('/foo/bar.ext/2', ('/foo/bar.ext', 2), True),
     ('/', ('/', 1), False),
@@ -53,7 +54,9 @@
 @pytest.mark.parametrize('uri, expected, pretty_urls', [
     ('/', ('/', 1), True),
     ('/2/', ('/', 2), True),
+    ('/foo/bar', ('/foo/bar/', 1), True),
     ('/foo/bar/', ('/foo/bar/', 1), True),
+    ('/foo/bar/2', ('/foo/bar/', 2), True),
     ('/foo/bar/2/', ('/foo/bar/', 2), True),
     ('/foo/bar.ext/', ('/foo/bar.ext/', 1), True),
     ('/foo/bar.ext/2/', ('/foo/bar.ext/', 2), True),
@@ -73,7 +76,9 @@
     ('/', ('/', 1), True),
     ('/2', ('/', 2), True),
     ('/foo/bar', ('/foo/bar', 1), True),
+    ('/foo/bar/', ('/foo/bar', 1), True),
     ('/foo/bar/2', ('/foo/bar', 2), True),
+    ('/foo/bar/2/', ('/foo/bar', 2), True),
     ('/foo/bar.ext', ('/foo/bar.ext', 1), True),
     ('/foo/bar.ext/2', ('/foo/bar.ext', 2), True),
     ('/', ('/', 1), False),