Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from zerocrates/xhtml-namespace
Browse files Browse the repository at this point in the history
Fix `TypeError` when using `Query` on XHTML, and namespace is implicitly used (#20)
  • Loading branch information
Ocramius authored Jun 7, 2022
2 parents 5e8571a + 89137c7 commit 8cc95ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected function getNodeList($document, $xpathQuery, ?DOMNode $contextNode = n
{
$xpath = new DOMXPath($document);
foreach ($this->xpathNamespaces as $prefix => $namespaceUri) {
$xpath->registerNamespace($prefix, $namespaceUri);
$xpath->registerNamespace((string) $prefix, $namespaceUri);
}
if ($this->xpathPhpFunctions) {
$xpath->registerNamespace("php", "http://php.net/xpath");
Expand Down
20 changes: 20 additions & 0 deletions test/QueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Dom;

use Laminas\Dom\Query;
use PHPUnit\Framework\TestCase;

class QueryTest extends TestCase
{
public function testXHTMLNamespaceRegistration()
{
$xhtml = '<?xml version="1.0"?><html xmlns="http://www.w3.org/1999/xhtml"></html>';
$query = new Query($xhtml);
$results = $query->queryXpath('/*');
$this->assertCount(1, $results);
$this->assertEquals('html', $results[0]->tagName);
}
}

0 comments on commit 8cc95ab

Please sign in to comment.