File tree 2 files changed +32
-7
lines changed
2 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -1665,14 +1665,28 @@ PHP_METHOD(Dom_XMLDocument, saveXml)
1665
1665
}
1666
1666
/* }}} end dom_document_savexml */
1667
1667
1668
+ static void dom_xinclude_strip_references_for_attributes (xmlNodePtr basep )
1669
+ {
1670
+ for (xmlAttrPtr prop = basep -> properties ; prop ; prop = prop -> next ) {
1671
+ php_libxml_node_free_resource ((xmlNodePtr ) prop );
1672
+ for (xmlNodePtr child = prop -> children ; child ; child = child -> next ) {
1673
+ php_libxml_node_free_resource (child );
1674
+ }
1675
+ }
1676
+ }
1677
+
1668
1678
static void dom_xinclude_strip_references (xmlNodePtr basep )
1669
1679
{
1670
1680
php_libxml_node_free_resource (basep );
1681
+ dom_xinclude_strip_references_for_attributes (basep );
1671
1682
1672
1683
xmlNodePtr current = basep -> children ;
1673
1684
1674
1685
while (current ) {
1675
1686
php_libxml_node_free_resource (current );
1687
+ if (current -> type == XML_ELEMENT_NODE ) {
1688
+ dom_xinclude_strip_references_for_attributes (current );
1689
+ }
1676
1690
current = php_dom_next_in_tree_order (current , basep );
1677
1691
}
1678
1692
}
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ $doc->loadXML(<<<XML
13
13
</xi:include>
14
14
<xi:test xmlns:xi="http://www.w3.org/2001/XInclude">
15
15
<xi:include href="thisisnonexistent">
16
- <p>garbage</p>
16
+ <p attr="foo" attr2="bar" >garbage</p>
17
17
</xi:include>
18
18
</xi:test>
19
19
</root>
@@ -22,20 +22,31 @@ XML);
22
22
$ xpath = new DOMXPath ($ doc );
23
23
24
24
$ garbage = [];
25
- foreach ($ xpath ->query ('//p ' ) as $ entry )
25
+ foreach ($ xpath ->query ('//p ' ) as $ entry ) {
26
26
$ garbage [] = $ entry ;
27
+ foreach ($ entry ->attributes as $ attr ) {
28
+ $ garbage [] = $ attr ;
29
+ foreach ($ attr ->childNodes as $ child ) {
30
+ $ garbage [] = $ child ;
31
+ }
32
+ }
33
+ }
27
34
28
35
@$ doc ->xinclude ();
29
36
30
37
foreach ($ garbage as $ node ) {
31
- try {
32
- var_dump ($ node ->localName );
33
- } catch (DOMException $ e ) {
34
- echo $ e ->getMessage (), "\n" ;
35
- }
38
+ try {
39
+ var_dump ($ node ->localName );
40
+ } catch (DOMException $ e ) {
41
+ echo $ e ->getMessage (), "\n" ;
42
+ }
36
43
}
37
44
?>
38
45
--EXPECT--
39
46
Invalid State Error
40
47
Invalid State Error
41
48
Invalid State Error
49
+ Invalid State Error
50
+ Invalid State Error
51
+ Invalid State Error
52
+ Invalid State Error
You can’t perform that action at this time.
0 commit comments