libxml2 r3701 - in trunk: . result result/noent test



Author: veillard
Date: Fri Mar  7 16:50:21 2008
New Revision: 3701
URL: http://svn.gnome.org/viewvc/libxml2?rev=3701&view=rev

Log:
* xmlsave.c parser.c: fix handling of empty CDATA nodes as 
  reported and discussed around #514181 and associated patches
* test/emptycdata.xml result/emptycdata.xml* 
  result/noent/emptycdata.xml: added a specific test in the
  regression suite.
Daniel


Added:
   trunk/result/emptycdata.xml
   trunk/result/emptycdata.xml.rde
   trunk/result/emptycdata.xml.rdr
   trunk/result/emptycdata.xml.sax
   trunk/result/emptycdata.xml.sax2
   trunk/result/noent/emptycdata.xml
   trunk/test/emptycdata.xml
Modified:
   trunk/ChangeLog
   trunk/parser.c
   trunk/xmlsave.c

Modified: trunk/parser.c
==============================================================================
--- trunk/parser.c	(original)
+++ trunk/parser.c	Fri Mar  7 16:50:21 2008
@@ -10165,7 +10165,20 @@
 			ctxt->input->cur += tmp;
 			goto encoding_error;
 		    }
-		    if ((ctxt->sax != NULL) && (base > 0) &&
+		    if ((ctxt->sax != NULL) && (base == 0) &&
+		        (ctxt->sax->cdataBlock != NULL) &&
+		        (!ctxt->disableSAX)) {
+			/*
+			 * Special case to provide identical behaviour
+			 * between pull and push parsers on enpty CDATA
+			 * sections
+			 */
+			 if ((ctxt->input->cur - ctxt->input->base >= 9) &&
+			     (!strncmp((const char *)&ctxt->input->cur[-9],
+			               "<![CDATA[", 9)))
+			     ctxt->sax->cdataBlock(ctxt->userData,
+			                           BAD_CAST "", 0);
+		    } else if ((ctxt->sax != NULL) && (base > 0) &&
 			(!ctxt->disableSAX)) {
 			if (ctxt->sax->cdataBlock != NULL)
 			    ctxt->sax->cdataBlock(ctxt->userData,

Added: trunk/result/emptycdata.xml
==============================================================================
--- (empty file)
+++ trunk/result/emptycdata.xml	Fri Mar  7 16:50:21 2008
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<![CDATA[]]>
+</html>

Added: trunk/result/emptycdata.xml.rde
==============================================================================
--- (empty file)
+++ trunk/result/emptycdata.xml.rde	Fri Mar  7 16:50:21 2008
@@ -0,0 +1,7 @@
+0 1 html 0 0
+1 14 #text 0 1 
+
+1 4 #cdata-section 0 1 
+1 14 #text 0 1 
+
+0 15 html 0 0

Added: trunk/result/emptycdata.xml.rdr
==============================================================================
--- (empty file)
+++ trunk/result/emptycdata.xml.rdr	Fri Mar  7 16:50:21 2008
@@ -0,0 +1,7 @@
+0 1 html 0 0
+1 14 #text 0 1 
+
+1 4 #cdata-section 0 1 
+1 14 #text 0 1 
+
+0 15 html 0 0

Added: trunk/result/emptycdata.xml.sax
==============================================================================
--- (empty file)
+++ trunk/result/emptycdata.xml.sax	Fri Mar  7 16:50:21 2008
@@ -0,0 +1,10 @@
+SAX.setDocumentLocator()
+SAX.startDocument()
+SAX.startElement(html, xmlns='http://www.w3.org/1999/xhtml')
+SAX.characters(
+, 1)
+SAX.pcdata(, 0)
+SAX.characters(
+, 1)
+SAX.endElement(html)
+SAX.endDocument()

Added: trunk/result/emptycdata.xml.sax2
==============================================================================
--- (empty file)
+++ trunk/result/emptycdata.xml.sax2	Fri Mar  7 16:50:21 2008
@@ -0,0 +1,10 @@
+SAX.setDocumentLocator()
+SAX.startDocument()
+SAX.startElementNs(html, NULL, 'http://www.w3.org/1999/xhtml', 1, xmlns='http://www.w3.org/1999/xhtml', 0, 0)
+SAX.characters(
+, 1)
+SAX.pcdata(, 0)
+SAX.characters(
+, 1)
+SAX.endElementNs(html, NULL, 'http://www.w3.org/1999/xhtml')
+SAX.endDocument()

Added: trunk/result/noent/emptycdata.xml
==============================================================================
--- (empty file)
+++ trunk/result/noent/emptycdata.xml	Fri Mar  7 16:50:21 2008
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<![CDATA[]]>
+</html>

Added: trunk/test/emptycdata.xml
==============================================================================
--- (empty file)
+++ trunk/test/emptycdata.xml	Fri Mar  7 16:50:21 2008
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<html xmlns="http://www.w3.org/1999/xhtml";>
+<![CDATA[]]>
+</html>

Modified: trunk/xmlsave.c
==============================================================================
--- trunk/xmlsave.c	(original)
+++ trunk/xmlsave.c	Fri Mar  7 16:50:21 2008
@@ -727,8 +727,8 @@
 	return;
     }
     if (cur->type == XML_CDATA_SECTION_NODE) {
-	if (cur->content == NULL) {
-		xmlOutputBufferWrite(buf, 12, "<![CDATA[]]>");
+	if (cur->content == NULL || *cur->content == '\0') {
+	    xmlOutputBufferWrite(buf, 12, "<![CDATA[]]>");
 	} else {
 	    start = end = cur->content;
 	    while (*end != '\0') {
@@ -1236,21 +1236,25 @@
 	return;
     }
     if (cur->type == XML_CDATA_SECTION_NODE) {
-	start = end = cur->content;
-	while (*end != '\0') {
-	    if (*end == ']' && *(end + 1) == ']' && *(end + 2) == '>') {
-		end = end + 2;
+	if (cur->content == NULL || *cur->content == '\0') {
+	    xmlOutputBufferWrite(buf, 12, "<![CDATA[]]>");
+	} else {
+	    start = end = cur->content;
+	    while (*end != '\0') {
+		if (*end == ']' && *(end + 1) == ']' && *(end + 2) == '>') {
+		    end = end + 2;
+		    xmlOutputBufferWrite(buf, 9, "<![CDATA[");
+		    xmlOutputBufferWrite(buf, end - start, (const char *)start);
+		    xmlOutputBufferWrite(buf, 3, "]]>");
+		    start = end;
+		}
+		end++;
+	    }
+	    if (start != end) {
 		xmlOutputBufferWrite(buf, 9, "<![CDATA[");
-		xmlOutputBufferWrite(buf, end - start, (const char *)start);
+		xmlOutputBufferWriteString(buf, (const char *)start);
 		xmlOutputBufferWrite(buf, 3, "]]>");
-		start = end;
 	    }
-	    end++;
-	}
-	if (start != end) {
-	    xmlOutputBufferWrite(buf, 9, "<![CDATA[");
-	    xmlOutputBufferWriteString(buf, (const char *)start);
-	    xmlOutputBufferWrite(buf, 3, "]]>");
 	}
 	return;
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]