Skip to content

Commit a5de752

Browse files
committed
Adjustment for namespace reconciliation revert
1 parent ac77f7f commit a5de752

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

ext/dom/html_document.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,13 @@ static void dom_post_process_html5_loading(xmlDocPtr lxml_doc, zend_long options
315315
}
316316
dom_place_remove_element_and_hoist_children((xmlNodePtr) lxml_doc, "html");
317317
if (!(options & DOM_HTML_NO_DEFAULT_NS) && EXPECTED(lxml_doc->children != NULL)) {
318-
dom_reconcile_ns_list(lxml_doc, lxml_doc->children, lxml_doc->last);
318+
xmlNodePtr node = lxml_doc->children;
319+
while (node) {
320+
/* Fine to use the DOM wrap reconciliation here because it's the "modern" world of DOM, and no user manipulation happened yet. */
321+
xmlDOMWrapCtxt dummy_ctxt = {0};
322+
xmlDOMWrapReconcileNamespaces(&dummy_ctxt, node, /* options */ 0);
323+
node = node->next;
324+
}
319325
}
320326
}
321327
}

ext/dom/tests/modern/html/parser/HTMLDocument_fromString_LIBXML_HTML_NOIMPLIED_namespace.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,41 @@ dom
55
--FILE--
66
<?php
77

8+
echo "--- No elements ---\n";
9+
10+
$dom = DOM\HTMLDocument::createFromString("", LIBXML_HTML_NOIMPLIED | LIBXML_NOERROR);
11+
echo $dom->saveXML();
12+
13+
echo "--- Single element ---\n";
14+
815
$dom = DOM\HTMLDocument::createFromString("<p>foo</p>", LIBXML_HTML_NOIMPLIED | LIBXML_NOERROR);
916
echo $dom->saveXML();
1017
var_dump($dom->documentElement->namespaceURI);
18+
var_dump($dom->documentElement->prefix);
19+
20+
echo "--- Multiple elements ---\n";
21+
22+
$dom = DOM\HTMLDocument::createFromString("<p>foo</p><strong>bar</strong>", LIBXML_HTML_NOIMPLIED | LIBXML_NOERROR);
23+
echo $dom->saveXML();
24+
var_dump($dom->documentElement->namespaceURI);
25+
var_dump($dom->documentElement->prefix);
26+
var_dump($dom->documentElement->nextSibling->namespaceURI);
27+
var_dump($dom->documentElement->nextSibling->prefix);
1128

1229
?>
1330
--EXPECT--
31+
--- No elements ---
32+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
33+
--- Single element ---
34+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
35+
<p xmlns="http://www.w3.org/1999/xhtml">foo</p>
36+
string(28) "http://www.w3.org/1999/xhtml"
37+
string(0) ""
38+
--- Multiple elements ---
1439
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1540
<p xmlns="http://www.w3.org/1999/xhtml">foo</p>
41+
<strong xmlns="http://www.w3.org/1999/xhtml">bar</strong>
42+
string(28) "http://www.w3.org/1999/xhtml"
43+
string(0) ""
1644
string(28) "http://www.w3.org/1999/xhtml"
45+
string(0) ""

0 commit comments

Comments
 (0)