diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index e59077aef22..804ec72e634 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -140,6 +140,7 @@ Sviatoslav Bulbakha Taha Jahangir Taras Voinarovskyi Terence Honles +Thijs Vermeir Thomas Grainger Tolga Tezel Vaibhav Sagar diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index 3fbf0742eb4..956d05b70b8 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -500,11 +500,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) @@ -513,7 +509,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 3cd7ecd10e0..737955ae958 100644 --- a/tests/test_web_urldispatcher.py +++ b/tests/test_web_urldispatcher.py @@ -29,17 +29,24 @@ 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