ahkscript / libcrypt.ahk

A collection of crypting and encoding functions from the community
MIT License
66 stars 19 forks source link

What is UrlEncode for? #20

Closed G33kDude closed 9 years ago

G33kDude commented 9 years ago

I'm not sure what that seemingly complicated RegEx filled function is for. Can someone explain?

joedf commented 9 years ago

encodeURI() vs. encodeURIComponent() ? http://xkr.us/articles/javascript/encode-compare/

G33kDude commented 9 years ago

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)

G33kDude commented 9 years ago

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?

joedf commented 9 years ago

It is to emulate the behaviour found in the address bar of a web browser. So, UrlEncode instead of UriEncore.

G33kDude commented 9 years ago

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:/;?@,&=+$#]")
}
joedf commented 9 years ago

Actually, that is in fact, quite ingenious!

G33kDude commented 9 years ago

It seems to me that that . should be added to the list of characters to keep on the UrlEncode

joedf commented 9 years ago

you mean for the http://example`.`com if so, that is what the regex needle is for : \w+:\/{0,2}[^\/]+.\/

G33kDude commented 9 years ago

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

joedf commented 9 years ago

actually, come to think of it... Go right on ahead :+1: