diff options
author | Jesse Wilson <jessewilson@google.com> | 2010-03-17 16:36:36 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-03-17 16:36:36 -0700 |
commit | b4d5b9454050d7fa0a6636d0955a4c8848e8f5a4 (patch) | |
tree | a6fa13969c31490b8ebd9b26258761d480e4ff0d | |
parent | 05d77746d9936ce913b6f4fa35c63e5945b0e7cb (diff) | |
parent | 03d1c3023ed8ff85ecb0a72d4f5615e6f81e31f6 (diff) | |
download | libcore-b4d5b9454050d7fa0a6636d0955a4c8848e8f5a4.zip libcore-b4d5b9454050d7fa0a6636d0955a4c8848e8f5a4.tar.gz libcore-b4d5b9454050d7fa0a6636d0955a4c8848e8f5a4.tar.bz2 |
am 31275264: Fixing 10 of the XPath failures caused by a malformed Document.
Merge commit '312752642a4539788952260fc517d286f6a6202e' into dalvik-dev
* commit '312752642a4539788952260fc517d286f6a6202e':
Fixing 10 of the XPath failures caused by a malformed Document.
-rw-r--r-- | xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java | 8 | ||||
-rw-r--r-- | xml/src/test/java/tests/xml/DomTest.java | 21 |
2 files changed, 25 insertions, 4 deletions
diff --git a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java index f3956f8..8bce9aa 100644 --- a/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java +++ b/xml/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java @@ -257,11 +257,11 @@ class DocumentBuilderImpl extends DocumentBuilder { } } else if (token == XmlPullParser.IGNORABLE_WHITESPACE) { /* - * Found some ignorable whitespace. We simply take the token - * text, but we only create a node if the client wants to see - * whitespace at all. + * Found some ignorable whitespace. We only add it if the client + * wants to see whitespace. Whitespace before and after the + * document element is always ignored. */ - if (!ignoreElementContentWhitespace) { + if (!ignoreElementContentWhitespace && document != node) { appendText(document, node, token, parser.getText()); } } else if (token == XmlPullParser.TEXT || token == XmlPullParser.CDSECT) { diff --git a/xml/src/test/java/tests/xml/DomTest.java b/xml/src/test/java/tests/xml/DomTest.java index 2f364d0..5f088c1 100644 --- a/xml/src/test/java/tests/xml/DomTest.java +++ b/xml/src/test/java/tests/xml/DomTest.java @@ -37,6 +37,7 @@ import org.w3c.dom.Text; import org.w3c.dom.TypeInfo; import org.w3c.dom.UserDataHandler; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -48,6 +49,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.io.File; import java.io.FileWriter; +import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.util.ArrayList; @@ -1311,6 +1313,25 @@ public class DomTest extends TestCase { } } + public void testDocumentDoesNotHaveWhitespaceChildren() + throws IOException, SAXException { + String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" + + " <foo/>\n" + + " \n"; + document = builder.parse(new InputSource(new StringReader(xml))); + assertEquals("Document nodes shouldn't have text children", + 1, document.getChildNodes().getLength()); + } + + public void testDocumentAddChild() + throws IOException, SAXException { + try { + document.appendChild(document.createTextNode(" ")); + fail("Document nodes shouldn't accept child nodes"); + } catch (DOMException e) { + } + } + private class RecordingHandler implements UserDataHandler { final Set<String> calls = new HashSet<String>(); public void handle(short operation, String key, Object data, Node src, Node dst) { |