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.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | b3949bc-12.patch | 570 bytes | tamas.varga |
Comments
Comment #1
patrickroma commentedAny news on this issue? We tried to find a workaround, but without success so far :-(
Comment #2
sansui commentedIt seems this issue was reported here http://drupal.org/node/826620 and marked as fixed, but I can confirm that is indeed not fixed.
Comment #3
patrickroma commentedhmmm... this is making me crazy... seems so simple, but still haven't found the right solution...
Comment #4
ducktape commentedI 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 .
Comment #5
patrickroma commentedHmmm... 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
Comment #6
sansui commentedYou 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
Comment #7
sansui commentedHrmm, 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.
Comment #8
ducktape commentedYes, 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.
Comment #9
sansui commentedYeah, 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.
Comment #10
patrickroma commentedI 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 268is given. I really have no clue. It's only shown with the quotes...Comment #11
moranpc commentedHas anyone found a solution ??
Comment #12
tamas.varga commentedFixed json encode.
Comment #13
szt commented