Closed vishalpai closed 11 years ago
Oh.
Any reason you introduce spanstartstring and spanendstring?
Umm...it was a quick fix...$(this.el).html() has the label enclosed by span....
i have a copy paste typo in there. I wonder how I managed to do that :)
var spanstartstring = ""; var spanendstring = "";
ok github comment screen also has a bug ;)...the spanstartstring has the span word enclosed in angular braces....and i cant type it here ;)....
due to the bug on github screen it shows that the spanstartstring is set to empty.
basically what i am doing is extracting the label between span start and end and then encoding the label and sticking in the serialized string.
var spanstartstring = "<span>";
var spanendstring = "</span>";
var label = $(this.el).html().substring(spanstartstring.length,$(this.el).html().length - spanendstring.length);
var encodedlabel = encodeURIComponent(label);
var finallabel = spanstartstring + encodedlabel + spanendstring;
var string = '{"label":"' + finallabel.replace(/'/g, '\\\'') + '","children":[';
there you go...lesson learnt is look at the preview before submit :)
first time github user and first time js code
okay and the single quote had to be handled separately using the replace. Not sure if its the right place to do it (cannot do it before encoding as \ would be encoded)
I think I was just replacing "
with \"
, because "
would collide with JSONs string literals, but encodeURIComponent takes care of "
, so we don't need this anymore, IMO
Why not just encode the tags, too? They get decoded anyway, afaik
hmm let me check the tag thing.. double quote not needed...but single quote is.
Ok, I think I fixed it. I completely ditched this en/de-codeURI stuff and adopted plain old JSON.{stringify/parse}, see my commit d0f1e1d7e955061...
Thanks for your help!
Thanks for fixing. I will check and get back.
In the mean time I have opened another one. Supporting cut and paste. I have provided a crude way to do it. Again serialize and de-serialize to the help.
Root reason: decodeURI used while loading data from json but corresponding encodeURI not used while serializing
Simple steps to reproduce:
Node.prototype.serialize = function () {
var spanstartstring = ""; var spanendstring = ""; var label = $(this.el).html().substring(spanstartstring.length,$(this.el).html().length - spanendstring.length); var encodedlabel = encodeURIComponent(label); var finallabel = spanstartstring + encodedlabel + spanendstring;
var string = '{"label":"' + finallabel.replace(/'/g, '\'') + '","children":[';
........... };