applied second patch from David Madore to be less intrusive when handling

* xmlsave.c: applied second patch from David Madore to be less intrusive
  when handling scripts and style elements in XHTML1 should fix #316041
* test/xhtml1 result//xhtml1\*: updated the test accordingly
Daniel
diff --git a/ChangeLog b/ChangeLog
index ab9ca48..3340827 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Sep 12 16:02:12 CEST 2005 Daniel Veillard <daniel@veillard.com>
+
+	* xmlsave.c: applied second patch from David Madore to be less intrusive
+	  when handling scripts and style elements in XHTML1 should fix #316041
+	* test/xhtml1 result//xhtml1\*: updated the test accordingly
+
 Mon Sep 12 15:09:09 CEST 2005 Daniel Veillard <daniel@veillard.com>
 
 	* libxml.spec.in doc/devhelp/*: finished the integration with
diff --git a/result/noent/xhtml1 b/result/noent/xhtml1
index d5179ee..6bc103a 100644
--- a/result/noent/xhtml1
+++ b/result/noent/xhtml1
@@ -7,7 +7,7 @@
   </head>
   <!-- 4.8 -->
   <script type="text/javascript"><![CDATA[
-  ... unescaped script content ...
+  ... unescaped script < content ...
   ]]></script>
   <body>
     <p>Moved to <a href="http://example.org/">example.org</a>.</p>
diff --git a/result/xhtml1 b/result/xhtml1
index d5179ee..6bc103a 100644
--- a/result/xhtml1
+++ b/result/xhtml1
@@ -7,7 +7,7 @@
   </head>
   <!-- 4.8 -->
   <script type="text/javascript"><![CDATA[
-  ... unescaped script content ...
+  ... unescaped script < content ...
   ]]></script>
   <body>
     <p>Moved to <a href="http://example.org/">example.org</a>.</p>
diff --git a/result/xhtml1.rde b/result/xhtml1.rde
index b7de2dd..4d2cc24 100644
--- a/result/xhtml1.rde
+++ b/result/xhtml1.rde
@@ -19,7 +19,7 @@
   
 1 1 script 0 0
 2 3 #text 0 1 
-  ... unescaped script content ...
+  ... unescaped script < content ...
   
 1 15 script 0 0
 1 14 #text 0 1 
diff --git a/result/xhtml1.rdr b/result/xhtml1.rdr
index b7de2dd..4d2cc24 100644
--- a/result/xhtml1.rdr
+++ b/result/xhtml1.rdr
@@ -19,7 +19,7 @@
   
 1 1 script 0 0
 2 3 #text 0 1 
-  ... unescaped script content ...
+  ... unescaped script < content ...
   
 1 15 script 0 0
 1 14 #text 0 1 
diff --git a/result/xhtml1.sax b/result/xhtml1.sax
index f71dd35..0dae3fb 100644
--- a/result/xhtml1.sax
+++ b/result/xhtml1.sax
@@ -22,7 +22,11 @@
   , 3)
 SAX.startElement(script, type='text/javascript')
 SAX.characters(
-  ... unescaped script conten, 38)
+  ... unescaped script , 24)
+SAX.getEntity(lt)
+SAX.characters(<, 1)
+SAX.characters( content ...
+  , 15)
 SAX.endElement(script)
 SAX.characters(
   , 3)
diff --git a/result/xhtml1.sax2 b/result/xhtml1.sax2
index 1ee84d9..969162e 100644
--- a/result/xhtml1.sax2
+++ b/result/xhtml1.sax2
@@ -22,7 +22,11 @@
   , 3)
 SAX.startElementNs(script, NULL, NULL, 0, 1, 0, type='text...', 15)
 SAX.characters(
-  ... unescaped script conten, 38)
+  ... unescaped script , 24)
+SAX.getEntity(lt)
+SAX.characters(<, 1)
+SAX.characters( content ...
+  , 15)
 SAX.endElementNs(script, NULL, NULL)
 SAX.characters(
   , 3)
diff --git a/test/xhtml1 b/test/xhtml1
index 3b5107a..70e3a34 100644
--- a/test/xhtml1
+++ b/test/xhtml1
@@ -9,7 +9,7 @@
   </head>
   <!-- 4.8 -->
   <script type="text/javascript">
-  ... unescaped script content ...
+  ... unescaped script &lt; content ...
   </script>
   <body>
     <p>Moved to <a href="http://example.org/">example.org</a>.</p>
diff --git a/xmlsave.c b/xmlsave.c
index fe5795e..b11172a 100644
--- a/xmlsave.c
+++ b/xmlsave.c
@@ -1321,25 +1321,26 @@
 	xmlNodePtr child = cur->children;
 
 	while (child != NULL) {
-	    if ((child->type == XML_TEXT_NODE) ||
-		(child->type == XML_CDATA_SECTION_NODE)) {
-		/*
-		 * Apparently CDATA escaping for style just break on IE,
-		 * mozilla and galeon, so ...
-		 */
-		if (xmlStrEqual(cur->name, BAD_CAST "style") &&
-		    (xmlStrchr(child->content, '<') == NULL) &&
-		    (xmlStrchr(child->content, '>') == NULL) &&
-		    (xmlStrchr(child->content, '&') == NULL)) {
+	    if (child->type == XML_TEXT_NODE) {
+		if ((xmlStrchr(child->content, '<') == NULL) &&
+		    (xmlStrchr(child->content, '&') == NULL) &&
+		    (xmlStrstr(child->content, BAD_CAST "]]>") == NULL)) {
+		    /* Nothing to escape, so just output as is... */
+		    /* FIXME: Should we do something about "--" also? */
 		    int level = ctxt->level;
 		    int indent = ctxt->format;
 
 		    ctxt->level = 0;
 		    ctxt->format = 0;
-		    xhtmlNodeDumpOutput(ctxt, child);
+		    xmlOutputBufferWriteString(buf, (const char *) child->content);
+		    /* (We cannot use xhtmlNodeDumpOutput() here because
+		     * we wish to leave '>' unescaped!) */
 		    ctxt->level = level;
 		    ctxt->format = indent;
 		} else {
+		    /* We must use a CDATA section.  Unfortunately,
+		     * this will break CSS and JavaScript when read by
+		     * a browser in HTML4-compliant mode. :-( */
 		    start = end = child->content;
 		    while (*end != '\0') {
 			if (*end == ']' &&