Browse Source

ZF-6143: applied patch from Mike Willibanks to check for empty documents

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16362 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 years ago
parent
commit
a5e39a2158
2 changed files with 18 additions and 3 deletions
  1. 4 3
      library/Zend/Dom/Query.php
  2. 14 0
      tests/Zend/Dom/QueryTest.php

+ 4 - 3
library/Zend/Dom/Query.php

@@ -65,9 +65,7 @@ class Zend_Dom_Query
      */
     public function __construct($document = null)
     {
-        if (null !== $document) {
-            $this->setDocument($document);
-        }
+        $this->setDocument($document);
     }
 
     /**
@@ -78,6 +76,9 @@ class Zend_Dom_Query
      */
     public function setDocument($document)
     {
+        if (0 === strlen($document)) {
+            return $this;
+        }
         if ('<?xml' == substr(trim($document), 0, 5)) {
             return $this->setDocumentXml($document);
         }

+ 14 - 0
tests/Zend/Dom/QueryTest.php

@@ -78,6 +78,20 @@ class Zend_Dom_QueryTest extends PHPUnit_Framework_TestCase
         $this->assertNull($this->query->getDocument());
     }
 
+    public function testDocShouldBeNullByEmptyStringConstructor()
+    {
+        $emptyStr = "";
+        $query = new Zend_Dom_Query($emptyStr);
+        $this->assertNull($this->query->getDocument());
+    }
+
+    public function testDocShouldBeNullByEmptyStringSet()
+    {
+        $emptyStr = "";
+        $this->query->setDocument($emptyStr);
+        $this->assertNull($this->query->getDocument());
+    }
+
     public function testDocTypeShouldBeNullByDefault()
     {
         $this->assertNull($this->query->getDocumentType());