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

Andreas Plesch andreasplesch at gmail.com
Tue Feb 28 03:57:04 PST 2017


Hm,

documentation for DOMParser points to this section

https://www.w3.org/TR/html5/single-page.html#xml-parser

It states that parsing rules from XML spec. are adopted.

However, a side note then mentions that there are no such rules in XML ...

Andreas


On Feb 27, 2017 10:22 PM, "Andreas Plesch" <andreasplesch at gmail.com> wrote:

It looks DOMParser.parseFromString should not unescape quoted escaped
characters in a cdata section. DOMParser is probably rigorously speced, so
it would be possible to find out the correct behavior.

Or does the unescaping already happen during string concatenation in the
previous line ?


On Feb 27, 2017 9:16 PM, <yottzumm at gmail.com> wrote:

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



John



Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
10



*From: *yottzumm at gmail.com
*Sent: *Monday, February 27, 2017 9:09 PM

*To: *Andreas Plesch <andreasplesch at gmail.com>; X3D Graphics public mailing
list <x3d-public at web3d.org>
*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 <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
10



*From: *yottzumm at gmail.com
*Sent: *Monday, February 27, 2017 8:46 PM
*To: *Andreas Plesch <andreasplesch at gmail.com>; X3D Graphics public mailing
list <x3d-public at web3d.org>
*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/20170228/4f3fffb4/attachment.html>


More information about the x3d-public mailing list