From 028a9096406eba26f823211b1f6a957ebc6b3a7b Mon Sep 17 00:00:00 2001
From: Miguel Gomez <magomez@igalia.com>
Date: Wed, 18 Sep 2013 11:18:54 +0200
Subject: New unit test to the DOMTree test suite

Ensure that a parsed document that contains a malformed xmlns tag
doesn't cause a segfault when serializing it through the
XSAXSerializable interface.

Change-Id: I00811494b37a307711c1a7a86403a56da8b23776
Reviewed-on: https://gerrit.libreoffice.org/6004
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
---
 unoxml/qa/complex/unoxml/DOMTest.java | 53 +++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

(limited to 'unoxml/qa')

diff --git a/unoxml/qa/complex/unoxml/DOMTest.java b/unoxml/qa/complex/unoxml/DOMTest.java
index 91a754ff0ae6..9191781e013f 100644
--- a/unoxml/qa/complex/unoxml/DOMTest.java
+++ b/unoxml/qa/complex/unoxml/DOMTest.java
@@ -25,8 +25,15 @@ import com.sun.star.uno.UnoRuntime;
 import com.sun.star.uno.XComponentContext;
 import com.sun.star.lang.XMultiServiceFactory;
 import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.StringPair;
 import com.sun.star.io.XInputStream;
+import com.sun.star.io.SequenceInputStream;
 import com.sun.star.xml.dom.*;
+import com.sun.star.xml.sax.XDocumentHandler;
+import com.sun.star.xml.sax.XSAXSerializable;
+import com.sun.star.xml.sax.SAXException;
+import com.sun.star.xml.sax.XAttributeList;
+import com.sun.star.xml.sax.XLocator;
 import static com.sun.star.xml.dom.DOMExceptionType.*;
 import static com.sun.star.xml.dom.NodeType.*;
 import com.sun.star.xml.xpath.*;
@@ -2686,6 +2693,52 @@ public class DOMTest
         }
     }
 
+    @Test public void testXSAXSerialize() throws Exception
+    {
+        String file =
+            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+            "<office:document-content " +
+            "xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" " +
+            "xmlns:xlink=\"http://www.w3.org/1999/xlink\" " +
+            "xmlns=\"\" " +
+            "office:version=\"1.0\">" +
+            "<office:scripts/>" +
+            "<xlink:test/>" +
+            "<office:automatic-styles teststyle=\"test\"/>" +
+            "<moretest/>" +
+            "some text \303\266\303\244\303\274" +
+            "</office:document-content>";
+
+        XDocumentBuilder xBuilder =
+            UnoRuntime.queryInterface(XDocumentBuilder.class,
+            m_xMSF.createInstance("com.sun.star.xml.dom.DocumentBuilder"));
+
+        XInputStream xIn =
+            SequenceInputStream.createStreamFromSequence(m_xContext, file.getBytes());
+
+        XDocument xDoc =
+            xBuilder.parse(xIn);
+
+        XDocumentHandler xHandler =
+            UnoRuntime.queryInterface(XDocumentHandler.class, new DummyDocumentHandler());
+
+        XSAXSerializable serializable =
+            UnoRuntime.queryInterface(XSAXSerializable.class, xDoc);
+
+        serializable.serialize(xHandler, new StringPair[0]);
+    }
+
+    class DummyDocumentHandler implements XDocumentHandler
+    {
+        public void startDocument() throws SAXException {}
+        public void endDocument() throws SAXException {}
+        public void startElement(String s, XAttributeList a) throws SAXException {}
+        public void endElement(String s) throws SAXException {}
+        public void characters(String s) throws SAXException {}
+        public void ignorableWhitespace(String s) throws SAXException {}
+        public void processingInstruction(String s1, String s2) throws SAXException {}
+        public void setDocumentLocator(XLocator l) throws SAXException {}
+    }
 
     // just for importNode...
     abstract class MockNode implements XNode
-- 
cgit