Ensure nav.homepage.url is not blank on error pages. (#1132)

Also maintain pattern of ending urls with a slash in nav (all non-error pages
do so the error page should also). A couple extra checks to ensure base_url
doesn't end in a slash though as it is expected that the string appended
to base_url will always begin with a slash.

Fixes #1131
This commit is contained in:
Waylan Limberg
2017-01-29 20:34:13 -05:00
committed by GitHub
parent 3c8a1fccca
commit daf97c282b
4 changed files with 12 additions and 11 deletions

View File

@@ -76,7 +76,8 @@ def get_global_context(nav, config):
return {
'nav': nav,
'base_url': nav.url_context.make_relative('/'),
# base_url should never end with a slash.
'base_url': nav.url_context.make_relative('/').rstrip('/'),
'extra_css': extra_css,
'extra_javascript': extra_javascript,

View File

@@ -97,7 +97,7 @@ class URLContext(object):
"""
if self.force_abs_urls:
abs_url = '%s/%s' % (self.base_path.rstrip('/'), utils.path_to_url(url.lstrip('/')))
return abs_url.rstrip('/')
return abs_url
suffix = '/' if (url.endswith('/') and len(url) > 1) else ''
# Workaround for bug on `os.path.relpath()` in Python 2.6

View File

@@ -325,10 +325,10 @@ class SiteNavigationTests(unittest.TestCase):
self.assertEqual([n.title for n in nav_items],
['Home', 'Running', 'Notes', 'License'])
self.assertEqual([n.url for n in nav_items], [
'',
'/api-guide/running',
'/about/notes',
'/about/sub/license'
'/',
'/api-guide/running/',
'/about/notes/',
'/about/sub/license/'
])
def test_force_abs_urls_with_base(self):
@@ -351,10 +351,10 @@ class SiteNavigationTests(unittest.TestCase):
self.assertEqual([n.title for n in nav_items],
['Home', 'Running', 'Notes', 'License'])
self.assertEqual([n.url for n in nav_items], [
'/foo',
'/foo/api-guide/running',
'/foo/about/notes',
'/foo/about/sub/license'
'/foo/',
'/foo/api-guide/running/',
'/foo/about/notes/',
'/foo/about/sub/license/'
])
def test_invalid_pages_config(self):

View File

@@ -286,7 +286,7 @@ def create_media_urls(nav, path_list):
continue
# We must be looking at a local path.
url = path_to_url(path)
relative_url = '%s/%s' % (nav.url_context.make_relative('/'), url)
relative_url = '%s/%s' % (nav.url_context.make_relative('/').rstrip('/'), url)
final_urls.append(relative_url)
return final_urls