[x3d-public] flaw in CDATACreateFunction in X3DJSONLD (from Andreas Plesch)

yottzumm at gmail.com yottzumm at gmail.com
Mon Feb 27 17:46:48 PST 2017


function CDATACreateFunction(document, element, str) {
        var domParser = new DOMParser();
        var cdataStr = '<script> <![CDATA[ ' + str + ' ]]> </script>'; // has to be wrapped into an element
        var scriptDoc = domParser .parseFromString (cdataStr, 'application/xml');
        var cdata = scriptDoc .children[0] .childNodes[1]; // space after script is childNode[0]
        element .appendChild(cdata);
}

If calling CDATACreateFunction(document, element, object[key].join("\r\n")+"\r\n");  like this, you may run into some difficulty when the DOM gets written out to XML or perhaps placed in a web page.  Namly, this:

"#sourceText":[
"ecmascript:",
"function set_position (value)",
"{",
"\tholdPosition=value;",
"}",
"function set_rotation (value)",
"{",
"\tBrowser.print ('Internal position=' + holdPosition.toString() + ' , internal rotation=' + value.toString() + '\n');",
"}"
]

Gets translated into this in XML

<![CDATA[ecmascript:
function set_position (value)
{
        holdPosition=value;
}
function set_rotation (value)
{
        Browser.print ('Internal position=' + holdPosition.toString() + ' , internal rotation=' + value.toString() + '
');
}
]]>

Note that the \n got converted into a newline.

I am working on this issue.

John

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/3ed8ae60/attachment.html>


More information about the x3d-public mailing list