changeset 396:dc0988d937b3

serve: Fix bug where `?!debug` doesn't get appending correctly. Add unit test.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 18 May 2015 15:35:52 -0700
parents 9e25852f058b
children 879b6b5647a8
files piecrust/routing.py tests/servings/test_debug_info.serve
diffstat 2 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/routing.py	Sun May 17 15:28:23 2015 -0700
+++ b/piecrust/routing.py	Mon May 18 15:35:52 2015 -0700
@@ -33,6 +33,7 @@
 
         self.pretty_urls = app.config.get('site/pretty_urls')
         self.trailing_slash = app.config.get('site/trailing_slash')
+        self.show_debug_info = app.config.get('site/show_debug_info')
         self.pagination_suffix_format = app.config.get(
                 '__cache/pagination_suffix_format')
         self.uri_root = app.config.get('site/root')
@@ -40,8 +41,6 @@
         uri = cfg['url']
         self.uri_pattern = uri.lstrip('/')
         self.uri_format = route_re.sub(self._uriFormatRepl, self.uri_pattern)
-        if app.config.get('site/show_debug_info'):
-            self.uri_format += '?!debug'
 
         # Get the straight-forward regex for matching this URI pattern.
         p = route_esc_re.sub(self._uriPatternRepl,
@@ -171,6 +170,10 @@
                     uri = base_uri + ext
 
         uri = self.uri_root + uri
+
+        if self.show_debug_info:
+            uri += '?!debug'
+
         return uri
 
     def slugifyTaxonomyTerm(self, term):
--- a/tests/servings/test_debug_info.serve	Sun May 17 15:28:23 2015 -0700
+++ b/tests/servings/test_debug_info.serve	Mon May 18 15:35:52 2015 -0700
@@ -14,3 +14,30 @@
 out_contains: |
     BLAH
     <div id="piecrust-debug-info"
+---
+url: /foo
+in:
+    pages/foo.md: BLAH {{pcurl('bar')}}
+out: BLAH /bar.html
+---
+url: /foo?!debug
+in:
+    pages/foo.md: BLAH {{pcurl('bar')}}
+out: BLAH /bar.html?!debug
+---
+url: /foo
+config:
+    site:
+        pretty_urls: true
+in:
+    pages/foo.md: BLAH {{pcurl('bar')}}
+out: BLAH /bar
+---
+url: /foo?!debug
+config:
+    site:
+        pretty_urls: true
+in:
+    pages/foo.md: BLAH {{pcurl('bar')}}
+out: BLAH /bar?!debug
+