tamland / kodi-plugin-routing

A routing module for kodi plugins
GNU General Public License v3.0
40 stars 12 forks source link

Variables are Escaped in Query, but Nowhere Else #32

Open da3dsoul opened 4 years ago

da3dsoul commented 4 years ago

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 commented 4 years ago

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

da3dsoul commented 4 years ago

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

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.