Просмотр исходного кода

ZF-12106: DomQuery fails to evaluate XPath when there are warnings

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24830 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 лет назад
Родитель
Сommit
d337c4be54
2 измененных файлов с 24 добавлено и 1 удалено
  1. 1 1
      library/Zend/Dom/Query.php
  2. 23 0
      tests/Zend/Dom/QueryTest.php

+ 1 - 1
library/Zend/Dom/Query.php

@@ -124,7 +124,7 @@ class Zend_Dom_Query
         }
         // breaking XML declaration to make syntax highlighting work
         if ('<' . '?xml' == substr(trim($document), 0, 5)) {
-            if (preg_match('/\?'.'>\s+<html[^>]*xmlns="([^"]+)"[^>]*>/i', $document, $matches)) {
+            if (preg_match('/<html[^>]*xmlns="([^"]+)"[^>]*>/i', $document, $matches)) {
                 $this->_xpathNamespaces[] = $matches[1];
                 return $this->setDocumentXhtml($document, $encoding);
             }

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

@@ -325,6 +325,29 @@ EOB;
         $this->query->setDocument($xhtmlWithXmlDecl, 'utf-8');
         $this->assertEquals(1, $this->query->query('//p')->count());
     }
+    
+    /**
+     * @group ZF-12106
+     */
+    public function testXhtmlDocumentWithXmlAndDoctypeDeclaration()
+    {
+        $xhtmlWithXmlDecl = <<<EOB
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html 
+     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <title>Virtual Library</title>
+  </head>
+  <body>
+    <p>Moved to <a href="http://example.org/">example.org</a>.</p>
+  </body>
+</html>
+EOB;
+        $this->query->setDocument($xhtmlWithXmlDecl, 'utf-8');
+        $this->assertEquals(1, $this->query->query('//p')->count());
+    }
 }
 
 // Call Zend_Dom_QueryTest::main() if this source file is executed directly.