xref: /php-src/ext/dom/tests/bug70359.phpt (revision d04f48b6)
1--TEST--
2Bug #70359 (print_r() on DOMAttr causes Segfault in php_libxml_node_free_list())
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8echo "-- Test without parent --\n";
9
10$dom = new DOMDocument();
11$dom->loadXML(<<<XML
12<?xml version="1.0" encoding="UTF-8"?>
13<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="fooooooooooooooooooooo"/>
14XML);
15$spaceNode = $dom->documentElement->getAttributeNode('xmlns');
16print_r($spaceNode);
17
18echo "-- Test with parent and non-ns attribute --\n";
19
20$dom = new DOMDocument();
21$dom->loadXML(<<<XML
22<?xml version="1.0" encoding="UTF-8"?>
23<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
24<url xmlns:xsi="fooooooooooooooooooooo" myattrib="bar"/>
25</urlset>
26XML);
27$spaceNode = $dom->documentElement->firstElementChild->getAttributeNode('myattrib');
28var_dump($spaceNode->nodeType);
29var_dump($spaceNode->nodeValue);
30
31$dom->documentElement->firstElementChild->remove();
32var_dump($spaceNode->parentNode);
33
34echo "-- Test with parent and ns attribute --\n";
35
36$dom = new DOMDocument();
37$dom->loadXML(<<<XML
38<?xml version="1.0" encoding="UTF-8"?>
39<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
40<url xmlns:xsi="fooooooooooooooooooooo" myattrib="bar"/>
41</urlset>
42XML);
43$spaceNode = $dom->documentElement->firstElementChild->getAttributeNode('xmlns:xsi');
44print_r($spaceNode);
45
46$dom->documentElement->firstElementChild->remove();
47var_dump($spaceNode->parentNode->nodeName); // Shouldn't crash
48
49?>
50--EXPECT--
51-- Test without parent --
52DOMNameSpaceNode Object
53(
54    [nodeName] => xmlns
55    [nodeValue] => http://www.sitemaps.org/schemas/sitemap/0.9
56    [nodeType] => 18
57    [prefix] =>
58    [localName] => xmlns
59    [namespaceURI] => http://www.sitemaps.org/schemas/sitemap/0.9
60    [isConnected] => 1
61    [ownerDocument] => (object value omitted)
62    [parentNode] => (object value omitted)
63    [parentElement] => (object value omitted)
64)
65-- Test with parent and non-ns attribute --
66int(2)
67string(3) "bar"
68NULL
69-- Test with parent and ns attribute --
70DOMNameSpaceNode Object
71(
72    [nodeName] => xmlns:xsi
73    [nodeValue] => fooooooooooooooooooooo
74    [nodeType] => 18
75    [prefix] => xsi
76    [localName] => xsi
77    [namespaceURI] => fooooooooooooooooooooo
78    [isConnected] => 1
79    [ownerDocument] => (object value omitted)
80    [parentNode] => (object value omitted)
81    [parentElement] => (object value omitted)
82)
83string(3) "url"
84