Skip to content

Commit

Permalink
Fix #3140 — enforce trailing slash for directories in auto
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Aug 25, 2018
1 parent c3625df commit d604423
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -20,6 +20,9 @@ Features
Bugfixes
--------

* Enforce trailing slash for directories in ``nikola auto``
(Issue #3140)

New in v8.0.0b3 (changes since Beta 2)
======================================

Expand Down
8 changes: 6 additions & 2 deletions nikola/plugins/command/auto/__init__.py
Expand Up @@ -38,7 +38,7 @@
import aiohttp
from aiohttp import web
from aiohttp.web_urldispatcher import StaticResource
from aiohttp.web_exceptions import HTTPNotFound, HTTPForbidden
from aiohttp.web_exceptions import HTTPNotFound, HTTPForbidden, HTTPMovedPermanently
from aiohttp.web_response import Response
from aiohttp.web_fileresponse import FileResponse
except ImportError:
Expand Down Expand Up @@ -432,7 +432,11 @@ def handle_file(self, request, filename, from_index=None):
if filename.endswith('/') or not filename:
ret = yield from self.handle_file(request, filename + 'index.html', from_index=filename)
else:
ret = yield from self.handle_file(request, filename + '/index.html', from_index=filename)
# Redirect and add trailing slash so relative links work (Issue #3140)
new_url = request.rel_url.path + '/'
if request.rel_url.query_string:
new_url += '?' + request.rel_url.query_string
raise HTTPMovedPermanently(new_url)
elif filepath.is_file():
ct, encoding = mimetypes.guess_type(str(filepath))
encoding = encoding or 'utf-8'
Expand Down

0 comments on commit d604423

Please sign in to comment.