[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/asobj/xml.cpp server/aso... |
Date: |
Mon, 14 May 2007 16:24:45 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/05/14 16:24:44
Modified files:
. : ChangeLog
server/asobj : xml.cpp xml.h
testsuite/actionscript.all: XML.as
Log message:
* server/asobj/xml.{cpp,h}: change extractNode interface to
return a
bool, so it can implement a custom ignoreWhite thing (the
libxml2
XML_PARSE_NOBLANKS seems to be not working. Add
getXMLOptions()
and getIgnoreWhite() utility methods (privates). Fixes bug
#19865.
* testsuite/actionscript.all/XML.as: more tests for ignoreWhite.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3200&r2=1.3201
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.cpp?cvsroot=gnash&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xml.h?cvsroot=gnash&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/actionscript.all/XML.as?cvsroot=gnash&r1=1.31&r2=1.32
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3200
retrieving revision 1.3201
diff -u -b -r1.3200 -r1.3201
--- ChangeLog 14 May 2007 14:52:52 -0000 1.3200
+++ ChangeLog 14 May 2007 16:24:43 -0000 1.3201
@@ -1,5 +1,13 @@
2007-05-14 Sandro Santilli <address@hidden>
+ * server/asobj/xml.{cpp,h}: change extractNode interface to return a
+ bool, so it can implement a custom ignoreWhite thing (the libxml2
+ XML_PARSE_NOBLANKS seems to be not working. Add getXMLOptions()
+ and getIgnoreWhite() utility methods (privates). Fixes bug #19865.
+ * testsuite/actionscript.all/XML.as: more tests for ignoreWhite.
+
+2007-05-14 Sandro Santilli <address@hidden>
+
* server/asobj/xmlnode.cpp (stringify): represent empty nodes with the
"<openclose />" format.
* server/asobj/xml.{cpp,h}: parseDoc made private; add clear()
Index: server/asobj/xml.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xml.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- server/asobj/xml.cpp 14 May 2007 14:37:37 -0000 1.41
+++ server/asobj/xml.cpp 14 May 2007 16:24:44 -0000 1.42
@@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-/* $Id: xml.cpp,v 1.41 2007/05/14 14:37:37 strk Exp $ */
+/* $Id: xml.cpp,v 1.42 2007/05/14 16:24:44 strk Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -233,7 +233,7 @@
call_method(method, &env, this, 0, 0);
}
-void
+bool
XML::extractNode(XMLNode& element, xmlNodePtr node, bool mem)
{
xmlAttrPtr attr;
@@ -271,19 +271,24 @@
element.nodeTypeSet(tText);
ptr = xmlNodeGetContent(node);
- if (ptr != NULL)
+ if (ptr == NULL) return false;
+ if (node->content)
{
- if ((strchr((const char *)ptr, '\n') == 0) && (ptr[0] != 0))
+ const char* in = reinterpret_cast<const char*>(ptr);
+ // XML_PARSE_NOBLANKS seems not to be working, so here's
+ // a custom implementation of it.
+ if ( ignoreWhite() )
{
- if (node->content)
+ if ( strspn(in, " \n\t\r") == strlen(in) )
{
- //log_msg(_("extractChildNode from text for %s has
contents '%s'"), node->name, ptr);
- std::string val(reinterpret_cast<const char*>(ptr));
- element.nodeValueSet(val);
+ log_msg("Text node value consists in blanks
only, discarding");
+ return false;
}
}
- xmlFree(ptr);
+ std::string val(in);
+ element.nodeValueSet(val);
}
+ xmlFree(ptr);
}
// See if we have any data (content)
@@ -293,10 +298,12 @@
{
child = new XMLNode();
child->setParent(&element);
- extractNode(*child, childnode, mem);
+ if ( ! extractNode(*child, childnode, mem) ) break;
element._children.push_back(child);
childnode = childnode->next;
}
+
+ return true;
}
/*private*/
@@ -318,9 +325,11 @@
{
boost::intrusive_ptr<XMLNode> child = new XMLNode();
child->setParent(this);
- extractNode(*child, cur, mem);
+ if ( extractNode(*child, cur, mem) )
+ {
_children.push_back(child);
}
+ }
return true;
}
@@ -348,8 +357,10 @@
// Clear current data
clear();
- xmlInitParser();
- _doc = xmlParseMemory(xml_in.c_str(), xml_in.size());
+ initParser();
+
+ //_doc = xmlParseMemory(xml_in.c_str(), xml_in.size());
+ _doc = xmlReadMemory(xml_in.c_str(), xml_in.size(), NULL, NULL,
getXMLOptions());
if (_doc == 0) {
log_error(_("Can't parse XML data"));
return false;
@@ -392,8 +403,8 @@
initParser();
- /// see: http://xmlsoft.org/html/libxml-parser.html#xmlParserOption
- int options = XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR;
+ int options = getXMLOptions();
+
_doc = xmlReadIO(readFromTuFile, closeTuFile, str.get(),
url.str().c_str(), NULL, options);
if ( str->get_error() )
{
@@ -418,15 +429,16 @@
_bytes_loaded = _bytes_total;
- parseDoc(_doc, false);
+ bool ret = parseDoc(_doc, false);
+
xmlCleanupParser();
xmlFreeDoc(_doc);
xmlMemoryDump();
- _loaded = 1;
+ _loaded = ret ? 1 : 0;
- onLoadEvent(true);
+ onLoadEvent(ret);
- return true;
+ return ret;
}
@@ -826,6 +838,37 @@
_attributes.clear();
}
+/*private*/
+bool
+XML::ignoreWhite() const
+{
+ // TODO: initialize this thing once...
+ std::string propname;
+ if ( VM::get().getSWFVersion() < 7 ) propname = "ignorewhite";
+ else propname = "ignoreWhite";
+
+ as_value val;
+ if ( ! const_cast<XML*>(this)->get_member(propname, &val) ) return false;
+ return val.to_bool();
+}
+
+/*private*/
+int
+XML::getXMLOptions() const
+{
+ int options = XML_PARSE_RECOVER | XML_PARSE_NOWARNING | XML_PARSE_NOERROR;
+
+ if ( ignoreWhite() )
+ {
+ // This doesn't seem to work, so the blanks skipping
+ // is actually implemented in XML::extractNode instead.
+ //log_msg("Adding XML_PARSE_NOBLANKS to options");
+ options |= XML_PARSE_NOBLANKS;
+ }
+
+ return options;
+}
+
} // end of gnash namespace
// Local Variables:
Index: server/asobj/xml.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xml.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- server/asobj/xml.h 14 May 2007 14:37:38 -0000 1.14
+++ server/asobj/xml.h 14 May 2007 16:24:44 -0000 1.15
@@ -161,6 +161,19 @@
/// Remove all childs
void clear();
+ /// \brief
+ /// Return true if ignoreWhite property was set to anythign evaluating
+ /// to true.
+ bool ignoreWhite() const;
+
+ /// Return the libxml2 options to use during parsing.
+ //
+ /// The options might depend on current XML object state, like
+ /// the 'ignoreWhite' parameter.
+ ///
+ /// See http://xmlsoft.org/html/libxml-parser.html#xmlParserOption
+ ///
+ int getXMLOptions() const;
/// Read in an XML document from the specified source
//
@@ -193,7 +206,10 @@
/// @param element
/// The XMLNode to initialize.
///
- void extractNode(XMLNode& element, xmlNodePtr node, bool mem);
+ /// @return false if the xmlNodePtr shouldn't exist
+ /// (ie: an all-blanks node with ignoreWhite set to true).
+ ///
+ bool extractNode(XMLNode& element, xmlNodePtr node, bool mem);
void setupFrame(gnash::as_object *xml, XMLNode *data, bool src);
Index: testsuite/actionscript.all/XML.as
===================================================================
RCS file: /sources/gnash/gnash/testsuite/actionscript.all/XML.as,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- testsuite/actionscript.all/XML.as 14 May 2007 14:52:52 -0000 1.31
+++ testsuite/actionscript.all/XML.as 14 May 2007 16:24:44 -0000 1.32
@@ -20,7 +20,7 @@
// compile this test case with Ming makeswf, and then
// execute it like this gnash -1 -r 0 -v out.swf
-rcsid="$Id: XML.as,v 1.31 2007/05/14 14:52:52 strk Exp $";
+rcsid="$Id: XML.as,v 1.32 2007/05/14 16:24:44 strk Exp $";
#include "dejagnu.as"
#include "utils.as"
@@ -696,18 +696,42 @@
xmlin2_out = "<X0><X1 /></X0>";
xmlin_stripwhite = "<X1T><X1C1 /><X1C2 /></X1T>";
-myxml2.ignoreWhite = false; // doesn't work w/out load ?
+myxml2.ignoreWhite = false;
myxml2.parseXML(xmlin);
check_equals(myxml2.childNodes.length, 1);
-xcheck_equals(myxml2.toString(), xmlin); // gnash fails discarding newlines
and tabs I think..
+check_equals(myxml2.toString(), xmlin);
myxml2.parseXML(xmlin2); // parsing twice doesn't append !
check_equals(myxml2.childNodes.length, 1);
check_equals(myxml2.toString(), xmlin2_out);
-myxml2.ignoreWhite = true; // doesn't work w/out load ?
+myxml2.ignoreWhite = true;
myxml2.parseXML(xmlin);
-xcheck_equals(myxml2.toString(), xmlin_stripwhite);
+check_equals(myxml2.toString(), xmlin_stripwhite);
+myxml2.ignoreWhite = true;
+myxml2.parseXML("<X1> </X1>");
+check_equals(myxml2.childNodes.length, 1);
+check(!myxml2.childNodes[0].hasChildNodes());
+check_equals(myxml2.toString(), "<X1 />");
+
+myxml2.ignoreWhite = false;
+myxml2.parseXML("<X1> </X1>");
+check_equals(myxml2.childNodes.length, 1);
+check(myxml2.childNodes[0].hasChildNodes());
+check_equals(myxml2.childNodes[0].childNodes[0].nodeType, 3); // text node
+check_equals(myxml2.childNodes[0].childNodes[0].nodeValue, ' '); // text node
+check_equals(myxml2.toString(), "<X1> </X1>");
+
+myxml2.ignoreWhite = true;
+myxml2.parseXML("<X1>
+</X1>");
+check_equals(myxml2.childNodes.length, 1);
+check(!myxml2.childNodes[0].hasChildNodes());
+check_equals(myxml2.toString(), "<X1 />");
+
+myxml2.ignoreWhite = true;
+myxml2.parseXML("<X1> t </X1>");
+check_equals(myxml2.toString(), "<X1> t </X1>");
// We're done
//totals();