How to properly handle escape characters?
-
Can anyone help me on handling escape characters?
Currently I got this code:editor.on("change", function(e){ var code = editor.getSession().getValue(); window.location.href = 'skp;editor_changed@' + code; });
What it does is sends editor's script to a ruby callback, but the escape characters are converted to nothing or sometimes raise an error. I need a way to properly handle escape characters, so that I can get the same script after passing code to ruby.
I'm pretty sure Aerilius done something similar with his Ruby Console +, but I don't have enough brains to understand it.
-
Such webdialog issues have been discussed in many places elsewhere (like here), I think it's not too far fetched to say the
skp:
protocol is unreliable and for many use cases "dead". It does not only need url-encoding (%
) + string escaping (\
), but it also looses certain combinations of characters. When it returns the string url-decoded to ruby it causes ruby to have issues with some decoded characters.I suggest to use
skp:
only for a small set of known identifiers of limited character range (names of your callbacks).
If you need to transfer user data (that could potentially contain any character like quotes or Chinese), let the Ruby API fetch the string from a hidden input field usingget_element_value
.Me and thomthom do this for all communication between Ruby and Webdialogs using a message pipe (see thomthom at github, or mine). Please don't waste too much valuable time with webdialog issues, but try to re-use what we have already worked out.
The purpose of an API interface is to hide its implementation details. It would be good if SketchUp incorporated a repaired or new communication model as default, so that developers can make plugins "on top" of the API instead of working around issues below the API.
-
@aerilius said:
let the Ruby API fetch the string from a hidden input field using
get_element_value
From my understanding, I should first assign editor.session().getValue() to the hidden input text and then use dlg.get_element_value("hidden_input_text")?
Edit:
Actually a hidden input does not allow multi lines. I used textarea withdisplay:none;
style instead. From my current observations the technique works amazing! -
@anton_s said:
Actually a hidden input does not allow multi lines. I used textarea with
display:none;
style instead. From my current observations the technique works amazing!Oh! ... ooh... I might have to revisit SKUI and check this.
Advertisement