Closed G33kDude closed 9 years ago
encodeURI()
vs. encodeURIComponent()
?
http://xkr.us/articles/javascript/encode-compare/
I can't think of how that encodeURI could be helpful; would you mind sharing a use case? Also, the "UrlEncode" functions that we have seem overly complicated, when they should just be copies of the "UriEncode" functions but with different encoding criteria (e.g. omitting a selection of special characters instead of just 0-9a-zA-Z
)
Ok, so I vaguely understand that it's supposed to just allow a wider range of special characters. My question now is what the point of the UrlDecode is? Shouldn't it just decode percent sequences like any normal decode?
It is to emulate the behaviour found in the address bar of a web browser. So, UrlEncode
instead of UriEncore
.
Oh, I just took a look at the actual UrlDeocde function and I see that it is indeed just a call to UriDecode. I see now. Would it be appropriate to rewrite UrlEncode to this, taking advantage of the new param on UriEncode?
LC_UrlEncode(Url) { ; keep ":/;?@,&=+$#"
return LC_UriEncode(Url, "[0-9a-zA-Z:/;?@,&=+$#]")
}
Actually, that is in fact, quite ingenious!
It seems to me that that .
should be added to the list of characters to keep on the UrlEncode
you mean for the http://example`.`com
if so, that is what the regex needle is for : \w+:\/{0,2}[^\/]+.\/
I had taken the comment ; keep ":/;?@,&=+$#"
literally, and implemented the function I suggested above in my local repo. I was referring to that function when I suggested to add .
to the list
actually, come to think of it... Go right on ahead :+1:
I'm not sure what that seemingly complicated RegEx filled function is for. Can someone explain?