When overcoming bug 336551 I have to even trim the string



8 years ago
8 years ago


(Reporter: Matěj Cepl, Unassigned)





8 years ago
Following the workaround on https://developer.mozilla.org/en/E4X for parsing a string into XML object is not enough. When I have this pieces of script:

function parseXMLBody(req) {
    var bodyStr = req.input.read();
    var XMLelem = null;
    if (req.isPost || req.isPut) {
        if ((!isUrlEncoded(req.contentType)) && (req.contentLength > 0)) {
            var respStr = bodyStr.decodeToString(req.charset);
            respStr = respStr.
                replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // Mozilla bug 336551
            XMLelem = new XML(respStr);
    return XMLelem;


    var atomNS = new Namespace("http://www.w3.org/2005/Atom");
    var entry = parseXMLBody(req);
    log.info("entry:\n" + entry);
    log.info("typeof entry: " + typeof entry);
    log.info("entry.updated: " + entry.atomNS::updated);

I get XML object, but entry.updated is apparently empty:

28785 [pool-1-thread-24] INFO  atomactions  - entry:
  <entry xmlns="http://www.w3.org/2005/Atom">    <title>John 3:17 or The Golden Middle Ground Between Grace and Sanctification?</title>    <id>urn:atomid:ceplovi.cz:atom1:blog:jan-3_17-2008-07-10</id>    <updated>2008-07-13T00:00:00+02:00</updated>    <content type="xhtml" xml:lang="en">      <div xmlns="http://www.w3.org/1999/xhtml">                        <p>There is a couple of things, which make for me sense together  	(and I am not sure, of course, whether they will make sense to you  	as well), and which I would like to record here.</p>        <p>“<span class="scripture">For God sent not his  	Son into the world to condemn the world; but that the world  	through him might be saved.</span>” (J. 3:17)  In some aspects and for some  	people (like me) and in certain moments, this is even more important  	than the previous verse, and yet it is quite rarely mentioned in the  	Church. Maybe because it so clear, that nobody gets much fame to explain  	(and there is not much to explain here?). For all of us, who live with  	the idea of God-policeman, following our doings to punish severely any  	small misstep, this is the good news.</p>        <p>There is quite certainly something significantly wrong            about preaching, that we always quote only  <em>(John                3:16)</em>  and we don’t continue one verse            further. As if we are still more interested in what’s            there in gospel for me, and we don’t understand, that            we are not the central figures in whole Bible. Not            that there wouldn’t be anything there for us, but …            that’s another long discussion I would like to have            with Dave.</p>      </div>    </content>  </entry>
28787 [pool-1-thread-24] INFO  atomactions  - typeof entry: xml
28788 [pool-1-thread-24] INFO  atomactions  - entry.updated: 
28788 [pool-1-thread-24] INFO  atomactions  - post.createtime: Invalid Date

The only solution I found (well, somebody on #ringojs channel ;)) is to trim input for XML constructor:

            respStr = respStr.
                replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "").
            XMLelem = new XML(respStr);

Then entry.updated has expected string content.

Complete repo with the code (and testing data) is on git://gitorious.org/coelodonta/coelodonta.git
You need to log in before you can comment on or make changes to this bug.