I think it expects a non-string object, but is passed a string when an atom is dropped from the library onto a CKeditor window. Please can you confirm if this is a bug, or if I'm misunderstanding how it should work.
Drupal.theme.prototype.scaldEmbed ends with this code, suggesting that "options" is a non-String object that needs to be stringified:
// If there are options, update the SAS representation.
if (options) {
output = output.replace(/<!-- scald=\d+(.+?) -->/, '<!-- scald=' + atom.sid + ':' + context + ' ' + JSON.stringify(options) + ' -->');
}But when an atom is dropped from the library onto a CKeditor window, the value that will be passed as "options" is built using sas2array, which just extracts the options substring from a SAS string.
So if the SAS for the atom is
[scald=105:sdl_editor_representation {"link":"http:/atom/33"}]
sas2array sets options to be
{"link":"http:/atom/33"}
after it runs through scaldEmbed it is output as
<div class="dnd-drop-wrapper"><!-- scald=105:sdl_editor_representation " {\"link\":\"http:/atom/33\"}" -->
This isn't the proper format. If I then try to right-click and edit the atom properties, the Link field in the pop-up window shows:
function link() { [native code] }
I'm trying to get this to work to implement setting a default value for a dropped atom (see issue https://drupal.org/node/2169385).
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | options-paramater-may-already-be-a-string-2227137-7.patch | 757 bytes | nagy.balint |
| #4 | options-paramater-may-already-be-a-string-2227137-2.patch | 750 bytes | scotwith1t |
Comments
Comment #1
jcisio commentedThe "options" can be either a string (for historical reason) or arbitrary data in "JSON-compatible" string.
The described behavior is indeed a bug. Drupal.theme.prototype.scaldEmbed should not JSONify the variable if it is already a string.
Comment #2
scotwith1tThis simple patch checks if the options variable is a string before JSON.stringify'ing it.
Comment #3
scotwith1tComment #4
scotwith1tOops. Wrong file.
Comment #5
nagy.balint commentedComment #6
nagy.balint commentedComment #7
nagy.balint commentedSeems we could use a trim there, as the function expects options to not have any whitespace before or after, and when it gets a string from sas2array then it will have a whitespace already before.
Comment #9
nagy.balint commentedThanks, Committed.