See the w3schools docs: http://www.w3schools.com/jsref/jsref_escape.asp Specifically the notes:
Note: The escape() and unescape() functions should not be used to encode or decode URIs. Use encodeURI() and decodeURI() functions instead!

Spiceee wrote:
Well, it's a GET request in the end so it's supposed to pull the trick.

Come to think of it, I've had to use it instead of escape() in the
past while passing vars to Flash Movies (which use utf8 by default).

If Prototype's supposed to work with a callback function that
escape()'s the query string it returns, then be warned that up to
1.5.1_rc1 it doesn't work with utf8 encoded pages/forms.

Regards,

Fabio.

On 4/2/07, Colin Mollenhour <[EMAIL PROTECTED]> wrote:
  
 (de|en)codeURIComponent is for sending via get/post specifically and not
much else afaik.. which is not the intended purpose of escape.


 Spiceee wrote:
 I'm using 1.5.1_rc1, since it's the last one with a Scriptaculous
release as well.

I've tried your snipped only it never gets passed



 var paramHash = paramString.toQueryParams();

 since it's the toQueryParams() call (with following decodeURIComponent
call) that seems to be the problem.

I've tried a couple of things, yelled "This is Sparta!!!!" a couple of
times to my macbook and finally realized it could be that Prototype is
using decodeURIComponent instead of unescape and the two functions
might handle those special latin chars differently in a pure utf8 env.
I've started using encodeURIComponent in the callback and things
started working.

I'm guessing this might come in handy to a lot of people, since
escape() is what's widely used in callback function examples for both
Prototype and Scriptaculous.

Cheers,

fabio.

On 4/1/07, Colin Mollenhour <[EMAIL PROTECTED]> wrote:


 What version of Prototype are you using? The 1.5.1_x versions convert
the parameters property into a hash using String#toQueryParams and then
back to a string using Hash.toQueryString so you might want to test your
callback string with these functions.. i.e.

callback:function(form, value) {
 var paramString = 'id=' + escape('137') + '&tags=' + escape(value);
 var paramHash = paramString.toQueryParams();
 if(paramString != Hash.toQueryString(paramHash)){
 alert('not equal!');
 }
 console.debug(paramString); //firebug
 console.debug(Hash.toQueryString(paramHash));
 return paramString;
}

If you get the "not equal!" alert or the same "malformed URI sequence"
error, let us know and report the problem on the Prototype:Core google
group.

Colin

Spiceee wrote:


 Hey,

Why would this "id=137&tags=com%E9dia%2C%20lala" spawn a
"malformed
URI sequence" error on both Firefox and Safari when using
InPlaceEditor?

All I'm doing is:

//<![CDATA[
 new Ajax.InPlaceEditor('tags', 'add_tags/', {rows:1,
callback:function(form, value) { return 'id=' + escape('137') +
'&tags=' + escape(value) }})
//]]>

When I remove the escape from the tags value the problem goes away (at
least for the utf8 encoded strings, which seems to be the source of
the problem), but if any special URI char is entered in tags (such as
&, = or ?) it spoils the whole query...

Firefox fails at this line of prototype:

 237 var value = pair[1] ? decodeURIComponent(pair[1]) : undefined;

Thanks,

fabio.








 >

    



  

--~--~---------~--~----~------------~-------~--~----~
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