Skip to content

URL Params are decoded too often #1474

Closed
@0xb35c

Description

Long story short

Passing a=%25s3 as a URL parameter causes an exception, saying "ValueError: Unallowed PCT %s3"
a=%25s3 is at some point decoded to a=%s3 and tried to parse as URL, which is of course invalid.

Expected behaviour

a=%25s3 should not be decoded to a=%s3

Actual behaviour

a=%25s3 is at some point decoded to a=%s3 and tried to parse as URL

Steps to reproduce

I debugged the whole issue. It seems the problem is in the file client_reqrep.py:77-81, where (if i understand correctly) the passed params (as dict) are merged with the params already in the URL.
Here is a code snippet showing the issue.

In [19]: URL('http://foo.bar').with_query(URL('http://bar.foo').with_query('a=%25').query)
Out[19]: URL('http://foo.bar/?a=')

In [20]: URL('http://bar.foo').with_query('a=%25')
Out[20]: URL('http://bar.foo/?a=%25')

In [21]: URL('http://bar.foo').with_query('a=%25').query
Out[21]: <MultiDictProxy('a': '%')>

Also here is some testcode:

import aiohttp
import asyncio

async def main(loop):
    params = {'key1': '%25s3', 'key2': 'value2'}
    with aiohttp.ClientSession() as session:
        async with session.get('http://127.0.0.1', params=params) as resp:
            print(resp.status)
            print(await resp.text())

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(loop))
    loop.close()

Your environment

  • Linux-Arch 4.8.11-1-ARCH
  • Python 3.5.2
  • aiohttp 1.1.4

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions