Skip to content

Commit 1c984a3

Browse files
committed
Add regression test with wrong output
1 parent 7eb3e9c commit 1c984a3

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

ext/dom/tests/bug80332.phpt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--TEST--
2+
Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument;
9+
10+
$doc->loadHTML('<span attr1="value1" attr2="value2"></span>');
11+
12+
$x = new DOMXPath($doc);
13+
$span = $x->query('//span')[0];
14+
15+
print "Node name: {$span->nodeName}\n";
16+
17+
function test($span, $key) {
18+
$key_formatted = match ($key) {
19+
false => 'false',
20+
true => 'true',
21+
null => 'null',
22+
default => is_string($key) ? "'$key'" : $key,
23+
};
24+
echo "Attribute [{$key_formatted}] name: ", $span->attributes[$key]->nodeName ?? '/', "\n";
25+
echo "Attribute [{$key_formatted}] value: ", $span->attributes[$key]->nodeValue ?? '/', "\n";
26+
echo "Attribute [{$key_formatted}] isset: ", isset($span->attributes[$key]) ? "yes" : "no", "\n";
27+
echo "\n";
28+
}
29+
30+
test($span, 0);
31+
test($span, false);
32+
test($span, true);
33+
test($span, null);
34+
test($span, 'attr2');
35+
// This one should fail because there is no 'hi' attribute
36+
test($span, 'hi');
37+
test($span, '0');
38+
test($span, '0.5');
39+
// This one should fail because it's out of bounds
40+
test($span, '2147483647');
41+
42+
?>
43+
--EXPECT--
44+
Node name: span
45+
Attribute [0] name: attr1
46+
Attribute [0] value: value1
47+
Attribute [0] isset: yes
48+
49+
Attribute [false] name: attr1
50+
Attribute [false] value: value1
51+
Attribute [false] isset: yes
52+
53+
Attribute [true] name: attr2
54+
Attribute [true] value: value2
55+
Attribute [true] isset: yes
56+
57+
Attribute [null] name: attr1
58+
Attribute [null] value: value1
59+
Attribute [null] isset: yes
60+
61+
Attribute ['attr2'] name: attr1
62+
Attribute ['attr2'] value: value1
63+
Attribute ['attr2'] isset: yes
64+
65+
Attribute ['hi'] name: attr1
66+
Attribute ['hi'] value: value1
67+
Attribute ['hi'] isset: yes
68+
69+
Attribute ['0'] name: attr1
70+
Attribute ['0'] value: value1
71+
Attribute ['0'] isset: yes
72+
73+
Attribute ['0.5'] name: attr1
74+
Attribute ['0.5'] value: value1
75+
Attribute ['0.5'] isset: yes
76+
77+
Attribute ['2147483647'] name: /
78+
Attribute ['2147483647'] value: /
79+
Attribute ['2147483647'] isset: no

0 commit comments

Comments
 (0)