views:

39

answers:

2

I have an uploadify component, which sends the files back to rails application. The problem I noticed at some point is, that for some special values data passed along are altered by the flash object.

On the client side I have

 $(document).ready(function() {
   $('#photo_image').uploadify({
    ...
    'scriptData': {
       authenticity_token = 'M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro='
     ...
     }
   });
 });

What Rails is getting:

"authenticity_token"=>"M  Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro="

When there is no '+' sign in the token everything works just fine. It looks like the flash is altering the string somehow. Any idea how to escape it? I tried CGI.escape, but result is exactly the same, '+' are stripped...

A: 

You have to use encodeURIComponent() to encode special characters:

$(document).ready(function() {
   $('#photo_image').uploadify({
    ...
    'scriptData': {
       authenticity_token = encodeURIComponent('M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro=')
     ...
     }
   });
 });
grobie
As far as I am aware JS encodeURIComponent is the equivalent of the CGI.escape or the "u" helper from Rails. Either way, that wasn't solving the problem. The problem is, that the uploadify does a lot coding/encoding on the way before passing the parameteres to the flash component. Actual solution is, to escape the token *twice*. So for example "encodeURIComponent(encodeURIComponent(token)))" or #{u u token}.
mdrozdziel
A: 

Actual solution is, to escape the token twice. So for example "encodeURIComponent(encodeURIComponent(token)))" or #{u u token}.

mdrozdziel