You're right, _YOU_ should do this in JavaScript.

encodeURIComponent and it's counterpart decodeURIComponent serve to
translate a single value of a URI into a transmission-safe Unicode
string.

http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Functions:encodeURIComponent
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Functions:decodeURIComponent
http://xkr.us/articles/javascript/encode-compare/

ASP.NET is doing something else here (I'm not an ASP.NET developer so
I have no idea as to what or why) but it's not valid behavior. A space
in Unicode is %20 whereas the '+' is just a commonly accepted
convention.

Therefor, rather than having this get added to Prototype.js for
everyone, it's better just to make sure you do this yourself in your
code. I use mod_perl and it understands that %20 is a space. If the
functionality of encodeURIComponent and decodeURIComponent really need
to be changed, we'd see Mozilla, Microsoft, and Opera changing them.
Not Prototype.js.

Good find though. I'm going to have to file this nugget away for the
day I get stuck writing some ASP.NET.

-E

On 3/29/07, Matthew <[EMAIL PROTECTED]> wrote:
>
> String.toQueryParams in Prototype.js doesn't decode querystring
> encoded by some programs properly because  'decodeURIComponent'
> doesn't convert charactor '+' to "%20". In some programs , such as
> 'Server.UrlEncode'  in ASP.NET, encode single whitespace as '+', not
> '%20'.
>
> For example:
>
> in ASP.NET web form
>
>   String s = "This is a test";
>   String encodedS = Server.UrlEncode(s);  // encodedS will be "This+is
> +a+test";
>
> But in javascirpt:
>
>   var encodedStringByAspNet = ""This+is+a+test";
>   var s = decodeURIComponent(encodedStringByAspNet ); // s will be
> "This+is+a+test". '+' s are not decoded!
>
> We can do this in javascript:
>
> var s = decodeURIComponent(encodedStringByAspNet.replace(/\+/g,
> "%20")); // s will be "This is a test." !
>
>
> I believe it will make String.toQueryParams more rebust.
>
>                                                            Best
> regards,
>
>
> Matthew
>
>
> >
>


-- 
Eric Ryan Harrison

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to