Skip to content

Commit

Permalink
Fix #782 regression: expand ~/path/to for static file serving
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Feb 15, 2016
1 parent 513c0e6 commit 2018386
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def __init__(self, name, prefix, directory, *,
self._prefix = prefix
self._prefix_len = len(self._prefix)
try:
directory = Path(directory).resolve()
directory = Path(directory)
if str(directory).startswith('~'):
directory = directory.expanduser()
directory = directory.resolve()
if not directory.is_dir():
raise ValueError('Not a directory')
except (FileNotFoundError, ValueError) as error:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,3 +874,12 @@ def test_resources_abc(self):
self.assertIsInstance(self.router.resources(), Sized)
self.assertIsInstance(self.router.resources(), Iterable)
self.assertIsInstance(self.router.resources(), Container)

def test_static_route_user_home(self):
here = pathlib.Path(aiohttp.__file__).parent
home = pathlib.Path('~').expanduser()
if not str(here).startswith(str(home)): # pragma: no cover
self.skipTest("aiohttp folder is not placed in user's HOME")
static_dir = '~/' + str(here.relative_to(home))
route = self.router.add_static('/st', static_dir)
self.assertEqual(here, route.get_info()['directory'])

0 comments on commit 2018386

Please sign in to comment.