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

yottzumm at gmail.com yottzumm at gmail.com
Mon Feb 27 18:16:57 PST 2017


Actually, it still could be in the client code.  Will have to develop some tests.

John

Sent from Mail for Windows 10

From: yottzumm at gmail.com
Sent: Monday, February 27, 2017 9:09 PM
To: Andreas Plesch; X3D Graphics public mailing list
Subject: RE: flaw in CDATACreateFunction in X3DJSONLD (from Andreas Plesch)

I was wrong.  It was in my serverside code.  So now, the serverside code looks like this:

        X3DJSONLD.setCDATACreateFunction(function(document, element, str) {
                // for script nodes
                var child = document.createCDATASection(str.replace(/\n'/g, "\\n'"));
                element.appendChild(child);
        });

FYI for those creating CDATA sections from JSON on the serverside.

John

Sent from Mail for Windows 10

From: yottzumm at gmail.com
Sent: Monday, February 27, 2017 8:46 PM
To: Andreas Plesch; X3D Graphics public mailing list
Subject: flaw in CDATACreateFunction in X3DJSONLD (from Andreas Plesch)

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/f0b23ae7/attachment.html>


More information about the x3d-public mailing list