Closed realjax closed 12 years ago
Hi
Not many people like that construct, but it breaks down to something like this:
var c = string_arr[i].match(reserved_chars);
if(c) {
// do this and that...
}
...so as you can see it's rather a test for whether the found char needs to be encoded or not.
That said: these functions (OAuth.urlEncode
and OAuth.urlDecode
) could be removed and use native encodeURI
and/or encodeURIComponent
.
Native encodeURI and encodeURIComponent only exist in the browser implementations of Javascript. I wrote them due to the fact I needed a cross platform way of percent encoding.
Also encodeURI and encodeURIComponent don't cover all characters that need to be encoded, which means some manual work anyway. I felt a fully manual approach was the best option to cover all my goals.
Native encodeURI and encodeURIComponent only exist in the browser implementations of Javascript. I wrote them due to the fact I needed a cross platform way of percent encoding.
Fair enough - I expected that this was the reasoning, I didn't expect that built in functions will not work according to the RFC :-( Bummer.
I stand corrected. :)
There are several standards in the RFC for percent encoding. Some are old and out of date. I believe one of these is the one that javascript uses.
This article explains the differences quite well http://www.marcworrell.com/article-2943-en.html
There are several standards in the RFC for percent encoding. Some are old and out of date. I believe one of these is the one that javascript uses.
This article explains the differences quite well http://www.marcworrell.com/article-2943-en.html
That's awesome stuff, I always (wrongly) assumed that there was only one specification to it.
TIL.
This method contains the following code:
.... for (i = 0; i < str_len; i++) { if (c = string_arr[i].match(reserved_chars)) { ...
I'm pretty sure that the assigment to c should be a comparison instead, should read:
.... for (i = 0; i < str_len; i++) { if (c == string_arr[i].match(reserved_chars)) { ...