xref: /PHP-8.3/ext/dom/tests/bug80602_3.phpt (revision b365fbd0)
1--TEST--
2Bug #80602 (Segfault when using DOMChildNode::before()) - use-after-free variation
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8$doc = new \DOMDocument();
9$doc->loadXML('<a>foo<last/></a>');
10$target = $doc->documentElement->lastChild;
11$target->before('bar', $doc->documentElement->firstChild, 'baz');
12echo $doc->saveXML($doc->documentElement), "\n";
13var_dump($target);
14
15$doc = new \DOMDocument();
16$doc->loadXML('<a>foo<last/></a>');
17$target = $doc->documentElement->lastChild;
18// Note: after instead of before
19$target->after('bar', $doc->documentElement->firstChild, 'baz');
20echo $doc->saveXML($doc->documentElement), "\n";
21var_dump($target);
22
23?>
24--EXPECTF--
25<a>barfoobaz<last/></a>
26object(DOMElement)#3 (27) {
27  ["schemaTypeInfo"]=>
28  NULL
29  ["tagName"]=>
30  string(4) "last"
31  ["className"]=>
32  string(0) ""
33  ["id"]=>
34  string(0) ""
35  ["firstElementChild"]=>
36  NULL
37  ["lastElementChild"]=>
38  NULL
39  ["childElementCount"]=>
40  int(0)
41  ["previousElementSibling"]=>
42  NULL
43  ["nextElementSibling"]=>
44  NULL
45  ["nodeName"]=>
46  string(4) "last"
47  ["nodeValue"]=>
48  string(0) ""
49  ["nodeType"]=>
50  int(1)
51  ["parentNode"]=>
52  string(22) "(object value omitted)"
53  ["parentElement"]=>
54  string(22) "(object value omitted)"
55  ["childNodes"]=>
56  string(22) "(object value omitted)"
57  ["firstChild"]=>
58  NULL
59  ["lastChild"]=>
60  NULL
61  ["previousSibling"]=>
62  string(22) "(object value omitted)"
63  ["nextSibling"]=>
64  NULL
65  ["attributes"]=>
66  string(22) "(object value omitted)"
67  ["isConnected"]=>
68  bool(true)
69  ["ownerDocument"]=>
70  string(22) "(object value omitted)"
71  ["namespaceURI"]=>
72  NULL
73  ["prefix"]=>
74  string(0) ""
75  ["localName"]=>
76  string(4) "last"
77  ["baseURI"]=>
78  string(%d) %s
79  ["textContent"]=>
80  string(0) ""
81}
82<a><last/>barfoobaz</a>
83object(DOMElement)#2 (27) {
84  ["schemaTypeInfo"]=>
85  NULL
86  ["tagName"]=>
87  string(4) "last"
88  ["className"]=>
89  string(0) ""
90  ["id"]=>
91  string(0) ""
92  ["firstElementChild"]=>
93  NULL
94  ["lastElementChild"]=>
95  NULL
96  ["childElementCount"]=>
97  int(0)
98  ["previousElementSibling"]=>
99  NULL
100  ["nextElementSibling"]=>
101  NULL
102  ["nodeName"]=>
103  string(4) "last"
104  ["nodeValue"]=>
105  string(0) ""
106  ["nodeType"]=>
107  int(1)
108  ["parentNode"]=>
109  string(22) "(object value omitted)"
110  ["parentElement"]=>
111  string(22) "(object value omitted)"
112  ["childNodes"]=>
113  string(22) "(object value omitted)"
114  ["firstChild"]=>
115  NULL
116  ["lastChild"]=>
117  NULL
118  ["previousSibling"]=>
119  NULL
120  ["nextSibling"]=>
121  string(22) "(object value omitted)"
122  ["attributes"]=>
123  string(22) "(object value omitted)"
124  ["isConnected"]=>
125  bool(true)
126  ["ownerDocument"]=>
127  string(22) "(object value omitted)"
128  ["namespaceURI"]=>
129  NULL
130  ["prefix"]=>
131  string(0) ""
132  ["localName"]=>
133  string(4) "last"
134  ["baseURI"]=>
135  string(%d) %s
136  ["textContent"]=>
137  string(0) ""
138}
139