I’m using a comment callback to add a comment from a web dialog to an item in my Plugin. Since special characters might be possible, I use the javascript function encodeUriComponent(str) to encode those characters.
For example, when I use skp:comment@107%3Dit's (which is skp:comment@107=it's) Sketchup crashes immediately, even if the callback is empty:
Because the callback always encloses its string within single-quotes you must escape any ' within the passed string.
e.g. in your it's the single-quote needs escaping, so you might think that "it\'s" would work, BUT when passing it to the callback you also need to escape the \ escape character itself !
So pass it as "it\\\'s"
Simply process the passed string through a replace function, so every ' becomes \\\'
But it appears to me that Sketchup itself can’t handle such a string, as it somewhere internally probably uses URI.unescape and encloses the result with ' at a later point which then crashes.
Yes, I can write my own escaping, that is not accidentally unescaped by Sketchup, but this doesn’t seem right to me.
Did you actually try skipping your own encoding trickery and simply using the ‘replace’ code example which I provided.
I find that it works for me just fine…
You saying that your method doesn’t work, is NOT the same as saying that mine is flaky !
Another alternative would be to replace the ’ characters in the string with ` in js, before the callback sends the string.
Then on the Ruby-side you can choose to either accept that back-quote or tr it into a ’ ?
If you never expect the back-quote then swapping to a ’ is OK ??
Not at work right now, but will do it tomorrow. I’m sure it’ll work, but why is that not a bug nonetheless? I’m not doing encoding trickery, Sketchup is and it fails while doing it. **I’m sending it%27s to a callback and Sketchup decides to unescape it in an unsafe/incorrect manner and fails. **