diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 686ef576560..10b91d61319 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -152,6 +152,7 @@ Taha Jahangir Taras Voinarovskyi Terence Honles Thanos Lefteris +Thijs Vermeir Thomas Grainger Tolga Tezel Vaibhav Sagar diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index c8b05191f73..23e95e3d0d3 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -492,11 +492,7 @@ def _directory_as_html(self, filepath): # sanity check assert filepath.is_dir() - posix_dir_len = len(self._directory.as_posix()) - - # remove the beginning of posix path, so it would be relative - # to our added static path - relative_path_to_dir = filepath.as_posix()[posix_dir_len:] + relative_path_to_dir = filepath.relative_to(self._directory).as_posix() index_of = "Index of /{}".format(relative_path_to_dir) head = "\n{}\n".format(index_of) h1 = "

{}

".format(index_of) @@ -505,7 +501,8 @@ def _directory_as_html(self, filepath): dir_index = filepath.iterdir() for _file in sorted(dir_index): # show file url as relative to static path - file_url = _file.as_posix()[posix_dir_len:] + file_url = self._prefix + '/' + \ + _file.relative_to(self._directory).as_posix() # if file is a directory, add '/' to the end of the name if _file.is_dir(): diff --git a/tests/test_web_urldispatcher.py b/tests/test_web_urldispatcher.py index f41a7d74575..6a37a7155ae 100644 --- a/tests/test_web_urldispatcher.py +++ b/tests/test_web_urldispatcher.py @@ -29,17 +29,23 @@ def teardown(): return tmp_dir -@pytest.mark.parametrize("show_index,status,data", - [(False, 403, None), - (True, 200, - b'\n\nIndex of /\n' - b'\n\n

Index of /

\n