Skip to content

Commit

Permalink
Fix normalize_path_middleware behavior for patch without slash (3669)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbag committed Mar 27, 2019
1 parent 2bf371e commit 1cf1156
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES/3669.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``web_middlewares.normalize_path_middleware`` behavior for patch without slash.
2 changes: 1 addition & 1 deletion aiohttp/web_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def impl(request: Request, handler: _Handler) -> StreamResponse:
if merge_slashes and append_slash:
paths_to_check.append(
re.sub('//+', '/', path + '/'))
if merge_slashes and remove_slash:
if merge_slashes and remove_slash and path.endswith('/'):
merged_slashes = re.sub('//+', '/', path)
paths_to_check.append(merged_slashes[:-1])

Expand Down
9 changes: 4 additions & 5 deletions tests/test_web_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ async def test_remove_trailing_when_necessary(self, path,
('/resource2?p1=1&p2=2', 404),
('/resource2/?p1=1&p2=2', 200),
('/resource2/a/b%2Fc', 404),
('/resource2/a/b%2Fc/', 200)
('/resource2/a/b%2Fc/', 200),
('/resource12', 404),
('/resource123456', 404),
])
async def test_no_trailing_slash_when_disabled(
self, path, status, cli):
Expand Down Expand Up @@ -271,10 +273,6 @@ async def test_remove_and_merge_slash(self, path, status, cli) -> None:
assert resp.status == status
assert resp.url.query == URL(path).query

async def test_cannot_remove_and_add_slash(self) -> None:
with pytest.raises(AssertionError):
web.normalize_path_middleware(append_slash=True, remove_slash=True)


async def test_old_style_middleware(loop, aiohttp_client) -> None:
async def handler(request):
Expand Down Expand Up @@ -425,6 +423,7 @@ async def handler(request):
return web.Response(body=b'OK')

class Middleware:

@web.middleware
async def call(self, request, handler):
resp = await handler(request)
Expand Down

0 comments on commit 1cf1156

Please sign in to comment.