Skip to content

Commit af17e55

Browse files
committed
Fix bug #80332
1 parent 2c53d63 commit af17e55

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ PHP NEWS
355355
- DOM:
356356
. Fixed bug #79451 (DOMDocument->replaceChild on doctype causes double free).
357357
(Nathan Freeman)
358+
. Fixed bug #80332 (Completely broken array access functionality with
359+
DOMNamedNodeMap). (Nathan Freeman)
358360

359361
- FPM:
360362
. Fixed bug GH-8885 (FPM access.log with stderr begins to write logs to

ext/dom/php_dom.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,18 @@ static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int
15191519
return NULL;
15201520
}
15211521

1522-
ZVAL_LONG(&offset_copy, zval_get_long(offset));
1522+
if (Z_TYPE_P(offset) == IS_STRING) {
1523+
zend_long lval;
1524+
zend_uchar type = is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), &lval, NULL, true);
1525+
if (type == IS_LONG) {
1526+
ZVAL_LONG(&offset_copy, lval);
1527+
} else {
1528+
zend_throw_error(NULL, "Cannot access node list with offset %s", Z_STRVAL_P(offset));
1529+
return NULL;
1530+
}
1531+
} else {
1532+
ZVAL_LONG(&offset_copy, zval_get_long(offset));
1533+
}
15231534

15241535
zend_call_method_with_1_params(object, object->ce, NULL, "item", rv, &offset_copy);
15251536

ext/dom/tests/bug80332.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument;
8+
$doc->loadHTML('<span attr1="value1" attr2="value2"></span>');
9+
10+
$x = new DOMXPath($doc);
11+
$span = $x->query('//span')[0];
12+
13+
print "Node name: {$span->nodeName}\n";
14+
print "Attribute [0] name: {$span->attributes[0]->nodeName}\n";
15+
print "Attribute [0] value: {$span->attributes[0]->nodeValue}\n";
16+
print "Attribute ['1'] name: {$span->attributes['1']->nodeName}\n";
17+
print "Attribute ['1'] value: {$span->attributes['1']->nodeValue}\n";
18+
print "Attribute 'hi' name: {$span->attributes['hi']->nodeName}\n";
19+
print "Attribute 'hi' value: {$span->attributes['hi']->nodeValue}\n";
20+
print "Attribute 'attr2' name: {$span->attributes['attr2']->nodeName}\n";
21+
print "Attribute 'attr2' value: {$span->attributes['attr2']->nodeValue}\n";
22+
?>
23+
--EXPECTF--
24+
Node name: span
25+
Attribute [0] name: attr1
26+
Attribute [0] value: value1
27+
Attribute ['1'] name: attr2
28+
Attribute ['1'] value: value2
29+
30+
Fatal error: Uncaught Error: Cannot access node list with offset hi in %s:%d
31+
Stack trace:
32+
#0 {main}
33+
thrown in %s on line %d

0 commit comments

Comments
 (0)