xref: /PHP-8.1/ext/dom/tests/bug80602.phpt (revision bffc7447)
1--TEST--
2Bug #80602 (Segfault when using DOMChildNode::before())
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7declare(strict_types=1);
8
9$doc = new \DOMDocument();
10$doc->loadXML('<a>foo<last/></a>');
11$target = $doc->documentElement->firstChild;
12$target->before($target);
13echo "1 ", $doc->saveXML($doc->documentElement).PHP_EOL;
14
15$doc = new \DOMDocument();
16$doc->loadXML('<a>foo<last/></a>');
17$target = $doc->documentElement->lastChild;
18$target->before($target);
19echo "2 ", $doc->saveXML($doc->documentElement).PHP_EOL;
20
21
22$doc = new \DOMDocument();
23$doc->loadXML('<a>foo<last/></a>');
24$target = $doc->documentElement->firstChild;
25$target->before($doc->documentElement->lastChild);
26echo "3 ", $doc->saveXML($doc->documentElement).PHP_EOL;
27
28$doc = new \DOMDocument();
29$doc->loadXML('<a>foo<last/></a>');
30$target = $doc->documentElement->lastChild;
31$target->before($doc->documentElement->firstChild);
32echo "4 ", $doc->saveXML($doc->documentElement).PHP_EOL;
33
34
35$doc = new \DOMDocument();
36$doc->loadXML('<a>foo<last/></a>');
37$target = $doc->documentElement->firstChild;
38$target->before($target, $doc->documentElement->lastChild);
39echo "5 ", $doc->saveXML($doc->documentElement).PHP_EOL;
40
41$doc = new \DOMDocument();
42$doc->loadXML('<a>foo<last/></a>');
43$target = $doc->documentElement->firstChild;
44$target->before($doc->documentElement->lastChild, $target);
45echo "6 ", $doc->saveXML($doc->documentElement).PHP_EOL;
46
47
48$doc = new \DOMDocument();
49$doc->loadXML('<a>foo<last/></a>');
50$target = $doc->documentElement->lastChild;
51$target->before($target, $doc->documentElement->firstChild);
52echo "7 ", $doc->saveXML($doc->documentElement).PHP_EOL;
53
54$doc = new \DOMDocument();
55$doc->loadXML('<a>foo<last/></a>');
56$target = $doc->documentElement->lastChild;
57$target->before($doc->documentElement->firstChild, $target);
58echo "8 ", $doc->saveXML($doc->documentElement).PHP_EOL;
59
60
61$doc = new \DOMDocument();
62$doc->loadXML('<a>foo<last/></a>');
63$target = $doc->documentElement->firstChild;
64$target->before('bar','baz');
65echo "9 ", $doc->saveXML($doc->documentElement).PHP_EOL;
66
67$doc = new \DOMDocument();
68$doc->loadXML('<a>foo<last/></a>');
69$target = $doc->documentElement->lastChild;
70$target->before('bar','baz');
71echo "10 ", $doc->saveXML($doc->documentElement).PHP_EOL;
72
73
74$doc = new \DOMDocument();
75$doc->loadXML('<a>foo<last/></a>');
76$target = $doc->documentElement->firstChild;
77$target->before($target, 'bar','baz');
78echo "11 ", $doc->saveXML($doc->documentElement).PHP_EOL;
79
80$doc = new \DOMDocument();
81$doc->loadXML('<a>foo<last/></a>');
82$target = $doc->documentElement->firstChild;
83$target->before('bar', $target, 'baz');
84echo "12 ", $doc->saveXML($doc->documentElement).PHP_EOL;
85
86$doc = new \DOMDocument();
87$doc->loadXML('<a>foo<last/></a>');
88$target = $doc->documentElement->firstChild;
89$target->before('bar', 'baz', $target);
90echo "13 ", $doc->saveXML($doc->documentElement).PHP_EOL;
91
92
93
94$doc = new \DOMDocument();
95$doc->loadXML('<a>foo<last/></a>');
96$target = $doc->documentElement->lastChild;
97$target->before($target, 'bar','baz');
98echo "14 ", $doc->saveXML($doc->documentElement).PHP_EOL;
99
100$doc = new \DOMDocument();
101$doc->loadXML('<a>foo<last/></a>');
102$target = $doc->documentElement->lastChild;
103$target->before('bar', $target, 'baz');
104echo "15 ", $doc->saveXML($doc->documentElement).PHP_EOL;
105
106$doc = new \DOMDocument();
107$doc->loadXML('<a>foo<last/></a>');
108$target = $doc->documentElement->lastChild;
109$target->before('bar', 'baz', $target);
110echo "16 ", $doc->saveXML($doc->documentElement).PHP_EOL;
111
112
113
114$doc = new \DOMDocument();
115$doc->loadXML('<a>foo<last/></a>');
116$target = $doc->documentElement->firstChild;
117$target->before('bar', $target, $doc->documentElement->lastChild);
118echo "17 ", $doc->saveXML($doc->documentElement).PHP_EOL;
119
120
121$doc = new \DOMDocument();
122$doc->loadXML('<a>foo<last/></a>');
123$target = $doc->documentElement->firstChild;
124$target->before($target, 'bar', $doc->documentElement->lastChild);
125echo "18 ", $doc->saveXML($doc->documentElement).PHP_EOL;
126
127
128$doc = new \DOMDocument();
129$doc->loadXML('<a>foo<last/></a>');
130$target = $doc->documentElement->firstChild;
131$target->before($target, $doc->documentElement->lastChild, 'bar');
132echo "19 ", $doc->saveXML($doc->documentElement).PHP_EOL;
133
134
135
136
137$doc = new \DOMDocument();
138$doc->loadXML('<a>foo<last/></a>');
139$target = $doc->documentElement->lastChild;
140$target->before('bar', $doc->documentElement->firstChild, $target);
141echo "20 ", $doc->saveXML($doc->documentElement).PHP_EOL;
142
143
144$doc = new \DOMDocument();
145$doc->loadXML('<a>foo<last/></a>');
146$target = $doc->documentElement->lastChild;
147$target->before($doc->documentElement->firstChild, 'bar', $target);
148echo "21 ", $doc->saveXML($doc->documentElement).PHP_EOL;
149
150
151$doc = new \DOMDocument();
152$doc->loadXML('<a>foo<last/></a>');
153$target = $doc->documentElement->lastChild;
154$target->before($doc->documentElement->firstChild, $target, 'bar');
155echo "22 ", $doc->saveXML($doc->documentElement).PHP_EOL;
156
157?>
158--EXPECTF--
1591 <a>foo<last/></a>
1602 <a>foo<last/></a>
1613 <a><last/>foo</a>
1624 <a>foo<last/></a>
1635 <a>foo<last/></a>
1646 <a><last/>foo</a>
1657 <a><last/>foo</a>
1668 <a>foo<last/></a>
1679 <a>barbazfoo<last/></a>
16810 <a>foobarbaz<last/></a>
16911 <a>foobarbaz<last/></a>
17012 <a>barfoobaz<last/></a>
17113 <a>barbazfoo<last/></a>
17214 <a>foo<last/>barbaz</a>
17315 <a>foobar<last/>baz</a>
17416 <a>foobarbaz<last/></a>
17517 <a>barfoo<last/></a>
17618 <a>foobar<last/></a>
17719 <a>foo<last/>bar</a>
17820 <a>barfoo<last/></a>
17921 <a>foobar<last/></a>
18022 <a>foo<last/>bar</a>
181