File tree Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Expand file tree Collapse file tree 3 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ PHP NEWS
10
10
11
11
- DOM:
12
12
. Fix weird unpack behaviour in DOM. (nielsdos)
13
+ . Fix xinclude destruction of live attributes. (nielsdos)
13
14
14
15
- GD:
15
16
. Fixed bug GH-17984 (calls with arguments as array with references).
Original file line number Diff line number Diff line change @@ -1607,14 +1607,28 @@ static zend_always_inline xmlNodePtr php_dom_next_in_tree_order(const xmlNode *n
1607
1607
}
1608
1608
}
1609
1609
1610
+ static void dom_xinclude_strip_references_for_attributes (xmlNodePtr basep )
1611
+ {
1612
+ for (xmlAttrPtr prop = basep -> properties ; prop ; prop = prop -> next ) {
1613
+ php_libxml_node_free_resource ((xmlNodePtr ) prop );
1614
+ for (xmlNodePtr child = prop -> children ; child ; child = child -> next ) {
1615
+ php_libxml_node_free_resource (child );
1616
+ }
1617
+ }
1618
+ }
1619
+
1610
1620
static void dom_xinclude_strip_references (xmlNodePtr basep )
1611
1621
{
1612
1622
php_libxml_node_free_resource (basep );
1623
+ dom_xinclude_strip_references_for_attributes (basep );
1613
1624
1614
1625
xmlNodePtr current = basep -> children ;
1615
1626
1616
1627
while (current ) {
1617
1628
php_libxml_node_free_resource (current );
1629
+ if (current -> type == XML_ELEMENT_NODE ) {
1630
+ dom_xinclude_strip_references_for_attributes (current );
1631
+ }
1618
1632
current = php_dom_next_in_tree_order (current , basep );
1619
1633
}
1620
1634
}
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,15 +22,22 @@ 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
var_dump ($ garbage );
31
38
?>
32
39
--EXPECT--
33
- array(3 ) {
40
+ array(7 ) {
34
41
[0]=>
35
42
object(DOMElement)#3 (1) {
36
43
["schemaTypeInfo"]=>
@@ -46,4 +53,24 @@ array(3) {
46
53
["schemaTypeInfo"]=>
47
54
NULL
48
55
}
56
+ [3]=>
57
+ object(DOMAttr)#10 (2) {
58
+ ["specified"]=>
59
+ bool(true)
60
+ ["schemaTypeInfo"]=>
61
+ NULL
62
+ }
63
+ [4]=>
64
+ object(DOMText)#13 (0) {
65
+ }
66
+ [5]=>
67
+ object(DOMAttr)#12 (2) {
68
+ ["specified"]=>
69
+ bool(true)
70
+ ["schemaTypeInfo"]=>
71
+ NULL
72
+ }
73
+ [6]=>
74
+ object(DOMText)#15 (0) {
75
+ }
49
76
}
You can’t perform that action at this time.
0 commit comments