Skip to content

Commit d604423

Browse files
committedAug 25, 2018
Fix #3140 — enforce trailing slash for directories in auto
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent c3625df commit d604423

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎CHANGES.txt

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Features
2020
Bugfixes
2121
--------
2222

23+
* Enforce trailing slash for directories in ``nikola auto``
24+
(Issue #3140)
25+
2326
New in v8.0.0b3 (changes since Beta 2)
2427
======================================
2528

‎nikola/plugins/command/auto/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import aiohttp
3939
from aiohttp import web
4040
from aiohttp.web_urldispatcher import StaticResource
41-
from aiohttp.web_exceptions import HTTPNotFound, HTTPForbidden
41+
from aiohttp.web_exceptions import HTTPNotFound, HTTPForbidden, HTTPMovedPermanently
4242
from aiohttp.web_response import Response
4343
from aiohttp.web_fileresponse import FileResponse
4444
except ImportError:
@@ -432,7 +432,11 @@ def handle_file(self, request, filename, from_index=None):
432432
if filename.endswith('/') or not filename:
433433
ret = yield from self.handle_file(request, filename + 'index.html', from_index=filename)
434434
else:
435-
ret = yield from self.handle_file(request, filename + '/index.html', from_index=filename)
435+
# Redirect and add trailing slash so relative links work (Issue #3140)
436+
new_url = request.rel_url.path + '/'
437+
if request.rel_url.query_string:
438+
new_url += '?' + request.rel_url.query_string
439+
raise HTTPMovedPermanently(new_url)
436440
elif filepath.is_file():
437441
ct, encoding = mimetypes.guess_type(str(filepath))
438442
encoding = encoding or 'utf-8'

0 commit comments

Comments
 (0)
Please sign in to comment.