changeset 752:7dbddfed8129

config: Fix how we parse the root URL to allow for absolute and user URLs.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 09 Jun 2016 23:32:15 -0700
parents 925f25ed9a54
children 9a92e2804562
files piecrust/appconfig.py
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/appconfig.py	Thu Jun 09 22:35:18 2016 -0700
+++ b/piecrust/appconfig.py	Thu Jun 09 23:32:15 2016 -0700
@@ -548,12 +548,18 @@
     return v
 
 
-# Make sure the site root starts and ends with a slash.
+# Make sure the site root ends with a slash.
 def _validate_site_root(v, values, cache):
-    if not v.startswith('/'):
-        raise ConfigurationError("The `site/root` setting must start "
-                                 "with a slash.")
-    root_url = urllib.parse.quote(v.rstrip('/') + '/')
+    url_bits = urllib.parse.urlparse(v)
+    if url_bits.params or url_bits.query or url_bits.fragment:
+        raise ConfigurationError("Root URL is invalid: %s" % v)
+
+    path = url_bits.path.rstrip('/') + '/'
+    if '%' not in path:
+        path = urllib.parse.quote(path)
+
+    root_url = urllib.parse.urlunparse((
+        url_bits.scheme, url_bits.netloc, path, '', '', ''))
     return root_url