-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix bug #80332 Completely broken array access functionality with DOMNamedNodeMap #10829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
#endif | ||
|
||
#include "php.h" | ||
|
||
#if defined(HAVE_LIBXML) && defined(HAVE_DOM) | ||
#include "ext/standard/php_rand.h" | ||
#include "php_dom.h" | ||
|
@@ -1519,7 +1520,14 @@ static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int | |
return NULL; | ||
} | ||
|
||
ZVAL_LONG(&offset_copy, zval_get_long(offset)); | ||
zend_long lval; | ||
if (Z_TYPE_P(offset) == IS_LONG) { | ||
ZVAL_LONG(&offset_copy, Z_LVAL_P(offset)); | ||
} else if (Z_TYPE_P(offset) == IS_STRING && is_numeric_string(Z_STRVAL_P(offset), Z_STRLEN_P(offset), &lval, NULL, false) == IS_LONG) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pretty big behavioural change, and a BC break. I think you need to place the numeric string check first, and only then fall back using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the ZPP (something like |
||
ZVAL_LONG(&offset_copy, lval); | ||
} else { | ||
return NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't just return NULL here, because in that case <?php
$doc = new DOMDocument;
$doc->loadHTML('<a href="https://example.com">hi!</a>');
$a = (new DOMXPath($doc))->query('//a')[0];
$a->attributes['href']->nodeValue = 'https://example.net';
print $doc->saveHTML(); |
||
} | ||
|
||
zend_call_method_with_1_params(object, object->ce, NULL, "item", rv, &offset_copy); | ||
|
||
|
@@ -1528,7 +1536,14 @@ static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int | |
|
||
static int dom_nodelist_has_dimension(zend_object *object, zval *member, int check_empty) | ||
{ | ||
zend_long offset = zval_get_long(member); | ||
zend_long lval; | ||
zend_long offset = -1; | ||
if (Z_TYPE_P(member) == IS_LONG) { | ||
offset = Z_LVAL_P(member); | ||
} else if (Z_TYPE_P(member) == IS_STRING && is_numeric_string(Z_STRVAL_P(member), Z_STRLEN_P(member), &lval, NULL, false) == IS_LONG) { | ||
offset = lval; | ||
} | ||
|
||
zval rv; | ||
|
||
if (offset < 0) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--TEST-- | ||
Bug #80332 (Completely broken array access functionality with DOMNamedNodeMap) | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
$doc = new DOMDocument; | ||
$doc->loadHTML('<span attr1="value1" attr2="value2"></span>'); | ||
|
||
$x = new DOMXPath($doc); | ||
$span = $x->query('//span')[0]; | ||
|
||
var_dump($span->attributes[0]->nodeName); | ||
var_dump($span->attributes[0]->nodeValue); | ||
|
||
var_dump($span->attributes['1']->nodeName); | ||
var_dump($span->attributes['1']->nodeValue); | ||
|
||
var_dump($span->attributes[0.6]->nodeName); | ||
var_dump($span->attributes[0.6]->nodeValue); | ||
|
||
var_dump($span->attributes['0.6']->nodeName); | ||
var_dump($span->attributes['0.6']->nodeValue); | ||
|
||
var_dump($span->attributes[12345678]->nodeName); | ||
var_dump($span->attributes[12345678]->nodeValue); | ||
|
||
var_dump($span->attributes['12345678']->nodeName); | ||
var_dump($span->attributes['12345678']->nodeValue); | ||
|
||
var_dump($span->attributes[9999999999999999999999999999999999]->nodeName); | ||
var_dump($span->attributes[9999999999999999999999999999999999]->nodeValue); | ||
|
||
var_dump($span->attributes['9999999999999999999999999999999999']->nodeName); | ||
var_dump($span->attributes['9999999999999999999999999999999999']->nodeValue); | ||
|
||
var_dump($span->attributes['hi']->nodeName); | ||
var_dump($span->attributes['hi']->nodeValue); | ||
?> | ||
--EXPECTF-- | ||
string(5) "attr1" | ||
string(6) "value1" | ||
string(5) "attr2" | ||
string(6) "value2" | ||
|
||
Warning: Attempt to read property "nodeName" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeValue" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeName" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeValue" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeName" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeValue" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeName" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeValue" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeName" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeValue" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeName" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeValue" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeName" on null in %s on line %d | ||
NULL | ||
|
||
Warning: Attempt to read property "nodeValue" on null in %s on line %d | ||
NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't do unrelated whitespace changes.