xref: /PHP-8.1/ext/dom/tests/bug80602_3.phpt (revision bffc7447)
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 (23) {
27  ["schemaTypeInfo"]=>
28  NULL
29  ["tagName"]=>
30  string(4) "last"
31  ["firstElementChild"]=>
32  NULL
33  ["lastElementChild"]=>
34  NULL
35  ["childElementCount"]=>
36  int(0)
37  ["previousElementSibling"]=>
38  NULL
39  ["nextElementSibling"]=>
40  NULL
41  ["nodeName"]=>
42  string(4) "last"
43  ["nodeValue"]=>
44  string(0) ""
45  ["nodeType"]=>
46  int(1)
47  ["parentNode"]=>
48  string(22) "(object value omitted)"
49  ["childNodes"]=>
50  string(22) "(object value omitted)"
51  ["firstChild"]=>
52  NULL
53  ["lastChild"]=>
54  NULL
55  ["previousSibling"]=>
56  string(22) "(object value omitted)"
57  ["nextSibling"]=>
58  NULL
59  ["attributes"]=>
60  string(22) "(object value omitted)"
61  ["ownerDocument"]=>
62  string(22) "(object value omitted)"
63  ["namespaceURI"]=>
64  NULL
65  ["prefix"]=>
66  string(0) ""
67  ["localName"]=>
68  string(4) "last"
69  ["baseURI"]=>
70  string(%d) %s
71  ["textContent"]=>
72  string(0) ""
73}
74<a><last/>barfoobaz</a>
75object(DOMElement)#2 (23) {
76  ["schemaTypeInfo"]=>
77  NULL
78  ["tagName"]=>
79  string(4) "last"
80  ["firstElementChild"]=>
81  NULL
82  ["lastElementChild"]=>
83  NULL
84  ["childElementCount"]=>
85  int(0)
86  ["previousElementSibling"]=>
87  NULL
88  ["nextElementSibling"]=>
89  NULL
90  ["nodeName"]=>
91  string(4) "last"
92  ["nodeValue"]=>
93  string(0) ""
94  ["nodeType"]=>
95  int(1)
96  ["parentNode"]=>
97  string(22) "(object value omitted)"
98  ["childNodes"]=>
99  string(22) "(object value omitted)"
100  ["firstChild"]=>
101  NULL
102  ["lastChild"]=>
103  NULL
104  ["previousSibling"]=>
105  NULL
106  ["nextSibling"]=>
107  string(22) "(object value omitted)"
108  ["attributes"]=>
109  string(22) "(object value omitted)"
110  ["ownerDocument"]=>
111  string(22) "(object value omitted)"
112  ["namespaceURI"]=>
113  NULL
114  ["prefix"]=>
115  string(0) ""
116  ["localName"]=>
117  string(4) "last"
118  ["baseURI"]=>
119  string(%d) %s
120  ["textContent"]=>
121  string(0) ""
122}
123