Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URIencode and colon

colon is a character which can be encoded to '%3A' as per many sites and when I try to encode using URIencode it is not working

for example if I try to encode like URIencode(':'); then nothing happens. colon is returned. Why is this?? can someone help me out here.

Thanks in advance.

like image 438
Jay Mayu Avatar asked Feb 14 '13 10:02

Jay Mayu


People also ask

Should colon be URL encoded?

Colon IS an invalid character in URL unless it is used for its purpose (for eg http://). "...Only alphanumerics [0-9a-zA-Z], the special characters "$-_. +! *'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL."

Is colon allowed in URL path?

It is completely fine to use a colon : in a URL path.

What does %2f mean in URL?

URL encoding converts characters into a format that can be transmitted over the Internet. - w3Schools. So, "/" is actually a seperator, but "%2f" becomes an ordinary character that simply represents "/" character in element of your url.


1 Answers

The encodeURI() encodes special characters, except:

, / ? : @ & = + $ #

You should use this instead encodeURIComponent(':');

This function encodes special characters. In addition, it encodes the characters skipped by encodeURI()

like image 130
Salman Avatar answered Oct 24 '22 20:10

Salman