Reputation: 1026
I'm using a Python handler to respond to an HTTP API. I'm reading some url params into the handler. There are some params which needs mandatory encoded strings. How can I check if the value of certain parameter is a regular string or a encoded string?
handler?u=https%3A%2F%2Fstackoverflow.com
Pass.
vs
handler?u=https://stackoverflow.com
Should fail as this is a plain string.
Appreciate your help.
Upvotes: 0
Views: 490
Reputation: 251106
You can compare the string with its unquoted version:
>>> import urlparse
>>> s1 = 'handler?u=https%3A%2F%2Fstackoverflow.com'
>>> s2 = 'handler?u=https://stackoverflow.com'
>>> urlparse.unquote(s1) == s1
False
>>> urlparse.unquote(s2) == s2
True
Upvotes: 2