SWFUpload throws this error if you type double quotes in the title or alt field.
Fatal error: Cannot use string offset as an array in modules/imagefield/imagefield_widget.inc on line 268

I don't have this issue with the standard image upload widget, so I guess that SWFUpload doesn't perform check_plain on the title/alt attribute.

CommentFileSizeAuthor
#12 b3949bc-12.patch570 bytestamas.varga

Comments

patrickroma’s picture

Any news on this issue? We tried to find a workaround, but without success so far :-(

sansui’s picture

It seems this issue was reported here http://drupal.org/node/826620 and marked as fixed, but I can confirm that is indeed not fixed.

patrickroma’s picture

hmmm... this is making me crazy... seems so simple, but still haven't found the right solution...

ducktape’s picture

I seem to have found the problem. Decoding the JSON response (in function swfupload_widget_value - swfupload_widget.inc) fails because there is a rogue double quote in there.
The JSON response gets built in function ref.updateStack (swfupload_widget.js). This line in particular adds the values from the extra form items :

ref.upload_stack[fid][name] = (input_field.attr('type') == 'checkbox') ? input_field.attr('checked') : input_field.val();

I don't have a patch for this, since I patched my version already with http://drupal.org/node/875706#comment-4295066, which changes that line.
This is line number 747 in beta8.

The value of the input field input_field.val() needs to be escaped for the JSON to work. Adding a simple .replace('"','\\"') seemed to work fine. This makes the new line:

ref.upload_stack[fid][name] = (input_field.attr('type') == 'checkbox') ? input_field.attr('checked') : input_field.val().replace('"','\\"');

I am not a Javascript guru, so there might be a better solutions out there. This doesn't fix other problems that might occur with the JSON decode .

patrickroma’s picture

Hmmm... doesn't work for me... Still " Double Quotes create the error:
Fatal error: Cannot use string offset as an array in modules/imagefield/imagefield_widget.inc on line 268

sansui’s picture

You might try this instead - .replace(/"/g, '\\"'); The global modifier will match all instead of just the first, in the case you have multiple double quotes.

BTW nice job thinking of that workaround ducktape :) You're right, it won't take care of other issues that might pop up, but so far I haven't found any. With this fix and chrome reordering possibly sorted out, seems like swfupload will be in a much more useable, stable state.

I would love to figure out why admin menu + swfupload causes tremendous browser lag though

sansui’s picture

Hrmm, spoke too soon

Once the quotes have been successfully added to the title/alt fields, the images can no longer be sorted without throwing the error again.

ducktape’s picture

Yes, the quotes don't get escape when you move the images around. The code is a couple lines above the line in mentioned in #5.

A simple replace doesn't seem to do it for this one though. I can't find a way to escape the double quote properly to send it to the server.

sansui’s picture

Yeah, I was unable to alter it in such a way as to keep the actual double quotes as well. The best I could come up with was just to replace it with an entity .replace(/"/g, '"');

It's not very pretty for the user when editing title/alt, but it allows double quotes to be displayed at least.

patrickroma’s picture

I tried with the fix from #9, but without success... Still the fatal error
Fatal error: Cannot use string offset as an array in modules/imagefield/imagefield_widget.inc on line 268 is given. I really have no clue. It's only shown with the quotes...

moranpc’s picture

Has anyone found a solution ??

tamas.varga’s picture

StatusFileSize
new570 bytes

Fixed json encode.

szt’s picture

Issue summary: View changes
Status: Active » Needs review