Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if string has already been URL encoded?

How could I check if string has already been encoded?

For example, if I encode TEST==, I get TEST%3D%3D. If I again encode last string, I get TEST%253D%253D, I would have to know before doing that if it is already encoded...

I have encoded parameters saved, and I need to search for them. I don't know for input parameters, what will they be - encoded or not, so I have to know if I have to encode or decode them before search.

like image 462
Trick Avatar asked Feb 19 '10 09:02

Trick


People also ask

What is URL encoded string?

URL Encoding (Percent Encoding) URL encoding converts characters into a format that can be transmitted over the Internet. URLs can only be sent over the Internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.

Is URL encoded PHP?

PHP | urlencode() Function. The urlencode() function is an inbuilt function in PHP which is used to encode the url. This function returns a string which consist all non-alphanumeric characters except -_. and replace by the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

What characters get URL encoded?

URL Encoding (Percent Encoding) A URL is composed from a limited set of characters belonging to the US-ASCII character set. These characters include digits (0-9), letters(A-Z, a-z), and a few special characters ( "-" , "." , "_" , "~" ).

Does browsers automatically encode URL?

"Browsers" don't do that. It may happen, that web sites or applications encode URLs this way if they are used in URL parameters: http://www.example.net/?url=http%3A%2F%2Fwww.example.com .


2 Answers

Decode, compare to original. If it does differ, original is encoded. If it doesn't differ, original isn't encoded. But still it says nothing about whether the newly decoded version isn't still encoded. A good task for recursion.

I hope one can't write a quine in urlencode, or this algorithm would get stuck.

Exception: When a string contains "+" character url decoder replaces it with a space even though the string is not url encoded

like image 125
SF. Avatar answered Sep 23 '22 18:09

SF.


Use regexp to check if your string contains illegal characters (i.e. characters which cannot be found in URL-encoded string, like whitespace).

like image 25
Roman Avatar answered Sep 25 '22 18:09

Roman