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

Variables are Escaped in Query, but Nowhere Else #32

Open
da3dsoul opened this issue Jan 12, 2020 · 2 comments
Open

Variables are Escaped in Query, but Nowhere Else #32

da3dsoul opened this issue Jan 12, 2020 · 2 comments

Comments

@da3dsoul
Copy link

The query strings are handled by the Python urllib urlencode(sequence) -> string and parse_qs(string) -> list(tuple). These handle escaping for you.
If you pass a variable to args or kwargs with the intention of them not going into the query, though, they are not escaped.

make_path():
args = tuple(quote_plus(str(a), '') for a in args)
...
url_kwargs = dict(((k, quote_plus(str(v), '')) for k, v in list(kwargs.items()) if k in self._keywords))

will escape in a place that reflects url_for and other important places, and

match():
...
return dict((k, unquote_plus(v)) for k, v in match.groupdict().items()) if match else None

will unescape it.

The important thing to note is that, theoretically, this could be a breaking change for some people, if they are expecting to handle that themselves. In most, if not all, cases, it should be fine, but it's better to bring it up here rather than put it in a PR to never see the light of day.

@dagwieers
Copy link
Contributor

It helps if you provide an example input, and what kind of input is incorrectly parsed.

@da3dsoul
Copy link
Author

Whatever needs escaping isn't. That applies to strings that:

  • have spaces
  • have Unicode
  • have URL reserved characters
  • have quotes or apostrophes
    Etc.

The easy way is to just use url_for and route to something like /drugs/are/<a> then give it anything like the above, let alone a full path.

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

No branches or pull requests

2 participants