0

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

2 Answers 2

0

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

$(document).ready(function() {
   $('#photo_image').uploadify({
    ...
    'scriptData': {
       authenticity_token = encodeURIComponent('M++Q3HNclKS7QBEM71lkF/8IkjTwr2JdtqJ4WNXVDro=')
     ...
     }
   });
 });
1
  • 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
    Commented Aug 10, 2010 at 6:08
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.