Skip to content

Commit

Permalink
fix #1140 (#1161)
Browse files Browse the repository at this point in the history
* fix #1140

fix #1140

* fix #1140
  • Loading branch information
vir-mir authored and asvetlov committed Sep 14, 2016
1 parent 0199e4a commit bb3c8f5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ CHANGES

- Publish ClientSession.loop property #1149

- Fix static file with spaces #1140

- Fix piling up asyncio loop by cookie expiration callbacks #1061

-
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,4 @@ Yusuke Tsutsumi
Марк Коренберг
Семён Марьясин
Pau Freixes
Alexey Firsov
2 changes: 1 addition & 1 deletion aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def get_info(self):

@asyncio.coroutine
def handle(self, request):
filename = request.match_info['filename']
filename = unquote(request.match_info['filename'])
try:
filepath = self._directory.joinpath(filename).resolve()
filepath.relative_to(self._directory)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,39 @@ def test_access_root_of_static_handler(tmp_dir_path, create_app_and_client,
yield from r.release()


@pytest.mark.parametrize('dir_name,filename,data', [
('', 'test file.txt', 'test text'),
('test dir name', 'test dir file .txt', 'test text file folder')
])
@asyncio.coroutine
def test_access_to_the_file_with_spaces(tmp_dir_path, create_app_and_client,
dir_name, filename, data):
"""
Checks operation of static files with spaces
"""

my_dir_path = os.path.join(tmp_dir_path, dir_name)

if dir_name:
os.mkdir(my_dir_path)

my_file_path = os.path.join(my_dir_path, filename)

with open(my_file_path, 'w') as fw:
fw.write(data)

app, client = yield from create_app_and_client()

url = os.path.join('/', dir_name, filename)

app.router.add_static('/', tmp_dir_path)

r = yield from client.get(url)
assert r.status == 200
assert (yield from r.text()) == data
yield from r.release()


@asyncio.coroutine
def test_access_non_existing_resource(tmp_dir_path, create_app_and_client):
"""
Expand Down

0 comments on commit bb3c8f5

Please sign in to comment.