comparison piecrust/appconfig.py @ 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 7705b3d981ca
children f6f9a284a5f3
comparison
equal deleted inserted replaced
751:925f25ed9a54 752:7dbddfed8129
546 if generators is None: 546 if generators is None:
547 v['generators'] = {} 547 v['generators'] = {}
548 return v 548 return v
549 549
550 550
551 # Make sure the site root starts and ends with a slash. 551 # Make sure the site root ends with a slash.
552 def _validate_site_root(v, values, cache): 552 def _validate_site_root(v, values, cache):
553 if not v.startswith('/'): 553 url_bits = urllib.parse.urlparse(v)
554 raise ConfigurationError("The `site/root` setting must start " 554 if url_bits.params or url_bits.query or url_bits.fragment:
555 "with a slash.") 555 raise ConfigurationError("Root URL is invalid: %s" % v)
556 root_url = urllib.parse.quote(v.rstrip('/') + '/') 556
557 path = url_bits.path.rstrip('/') + '/'
558 if '%' not in path:
559 path = urllib.parse.quote(path)
560
561 root_url = urllib.parse.urlunparse((
562 url_bits.scheme, url_bits.netloc, path, '', '', ''))
557 return root_url 563 return root_url
558 564
559 565
560 # Cache auto-format regexes, check that `.html` is in there. 566 # Cache auto-format regexes, check that `.html` is in there.
561 def _validate_site_auto_formats(v, values, cache): 567 def _validate_site_auto_formats(v, values, cache):