Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent double-encoding of path components in queries. #252

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aioelasticsearch/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def perform_request(
):
url_path = url

url = (self.base_url / url.lstrip('/')).with_query(params)
url = self.base_url.join(URL.build(path=url.lstrip('/'), encoded=True)).with_query(params)

start = self.loop.time()
try:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import asyncio
import ssl
from unittest import mock
from urllib.parse import unquote

import aiohttp
import pytest
from elasticsearch import ConnectionTimeout
from elasticsearch.client.utils import _make_path

from aioelasticsearch.connection import (AIOHttpConnection, ConnectionError,
SSLError)
Expand Down Expand Up @@ -114,3 +116,23 @@ async def coro(*args, **Kwargs):
use_ssl=True))
with pytest.raises(expected):
await conn.perform_request('HEAD', '/')


@pytest.mark.run_loop
async def test_path_encoding(loop):
class StopProcessing(Exception):
pass

class DummyClientSession(object):
def request(self, method, url, **kwargs):
raise StopProcessing(unquote(url.path))

conn = AIOHttpConnection(session=DummyClientSession(), loop=loop)

for id in ("123abc", "123+abc", "123%4"):
path = _make_path("index", "_doc", id)

with pytest.raises(StopProcessing) as sp:
await conn.perform_request("GET", path)

assert id == str(sp.value).split("/")[-1]