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

Regression: params doesn't permit & and # in values #282

Closed
twm opened this issue Apr 5, 2020 · 0 comments · Fixed by #283
Closed

Regression: params doesn't permit & and # in values #282

twm opened this issue Apr 5, 2020 · 0 comments · Fixed by #283
Assignees
Labels

Comments

@twm
Copy link
Contributor

twm commented Apr 5, 2020

The new params merging code in 20.3.0 regressed: it now forbids the characters & and # in param values.

This is because we're using hyperlink.URL (a.k.a. hyperlink.EncodedURL) when we want hyperlink.DecodedURL.

For example:

from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks

import treq


@inlineCallbacks
def main(reactor):
    print('Preserved query parameters')
    resp = yield treq.get('https://httpbin.org/get?foo=bar',
                          params={'baz': 'b&x'})
    content = yield resp.text()
    print(content)

react(main, [])

Produces an exception:

Traceback (most recent call last):
  File "docs/examples/query_params.py", line 15, in <module>
    react(main, [])
...
  File "docs/examples/query_params.py", line 11, in main
    params={'baz': 'b&x'})
  File "/home/twm/treq/src/treq/api.py", line 24, in get
    return _client(**kwargs).get(url, headers=headers, **kwargs)
  File "/home/twm/treq/src/treq/client.py", line 119, in get
    return self.request('GET', url, **kwargs)
  File "/home/twm/treq/src/treq/client.py", line 172, in request
    query=parsed_url.query + tuple(_coerced_query_params(params))
  File "/home/twm/treq/.tox/py37-twisted_latest/lib/python3.7/site-packages/hyperlink/_url.py", line 1085, in replace
    uses_netloc=_optional(uses_netloc, self.uses_netloc)
  File "/home/twm/treq/.tox/py37-twisted_latest/lib/python3.7/site-packages/hyperlink/_url.py", line 838, in __init__
    for k, v in iter_pairs(query))
  File "/home/twm/treq/.tox/py37-twisted_latest/lib/python3.7/site-packages/hyperlink/_url.py", line 838, in <genexpr>
    for k, v in iter_pairs(query))
  File "/home/twm/treq/.tox/py37-twisted_latest/lib/python3.7/site-packages/hyperlink/_url.py", line 475, in _textcheck
    % (''.join(delims), name, value))
builtins.ValueError: one or more reserved delimiters &# present in query parameter value: 'b&x'

I filed python-hyper/hyperlink#125 about getting the latter documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant