rrichards Mon Aug 28 23:36:23 2006 UTC
Added files: (Branch: PHP_5_2)
/php-src/ext/dom/tests bug38474.phpt
Modified files:
/php-src/ext/dom element.c
Log:
fix #38474 (getAttribute select attribute by order, even when prefixed)
add test
http://cvs.php.net/viewvc.cgi/php-src/ext/dom/element.c?r1=1.36.2.4.2.2&r2=1.36.2.4.2.3&diff_format=u
Index: php-src/ext/dom/element.c
diff -u php-src/ext/dom/element.c:1.36.2.4.2.2
php-src/ext/dom/element.c:1.36.2.4.2.3
--- php-src/ext/dom/element.c:1.36.2.4.2.2 Tue Jun 13 20:19:37 2006
+++ php-src/ext/dom/element.c Mon Aug 28 23:36:23 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: element.c,v 1.36.2.4.2.2 2006/06/13 20:19:37 iliaa Exp $ */
+/* $Id: element.c,v 1.36.2.4.2.3 2006/08/28 23:36:23 rrichards Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -188,7 +188,24 @@
/* }}} */
-
+static xmlAttrPtr dom_get_dom1_attribute(xmlNodePtr elem, xmlChar *name) {
+ int len;
+ const xmlChar *nqname;
+
+ nqname = xmlSplitQName3(name, &len);
+ if (nqname != NULL) {
+ xmlNsPtr ns;
+ xmlChar *prefix = xmlStrndup(name, len);
+ ns = xmlSearchNs(elem->doc, elem, prefix);
+ if (prefix != NULL) {
+ xmlFree(prefix);
+ }
+ if (ns != NULL) {
+ return xmlHasNsProp(elem, nqname, ns->href);
+ }
+ }
+ return xmlHasNsProp(elem, name, NULL);
+}
/* {{{ proto string dom_element_get_attribute(string name);
URL:
http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-666EE0F9
@@ -198,8 +215,9 @@
{
zval *id;
xmlNode *nodep;
- char *name, *value;
+ char *name, *value = NULL;
dom_object *intern;
+ xmlAttrPtr attr;
int name_len;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
"Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
@@ -208,7 +226,15 @@
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
- value = xmlGetProp(nodep, name);
+ attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
+ if (attr) {
+ if (attr->type == XML_ATTRIBUTE_NODE) {
+ value = xmlNodeListGetString(attr->doc, attr->children,
1);
+ } else {
+ value =
xmlStrdup(((xmlAttributePtr)attr)->defaultValue);
+ }
+ }
+
if (value == NULL) {
RETURN_EMPTY_STRING();
} else {
@@ -232,7 +258,6 @@
dom_object *intern;
char *name, *value;
-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
"Oss", &id, dom_element_class_entry, &name, &name_len, &value, &value_len) ==
FAILURE) {
return;
}
@@ -249,7 +274,7 @@
RETURN_FALSE;
}
- attr = xmlHasProp(nodep,name);
+ attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
if (attr != NULL && attr->type != XML_ATTRIBUTE_DECL) {
node_list_unlink(attr->children TSRMLS_CC);
}
@@ -289,7 +314,7 @@
RETURN_FALSE;
}
- attrp = xmlHasProp(nodep,name);
+ attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
if (attrp == NULL) {
RETURN_FALSE;
}
@@ -328,7 +353,7 @@
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
- attrp = xmlHasProp(nodep,name);
+ attrp = dom_get_dom1_attribute(nodep, (xmlChar *)name);
if (attrp == NULL) {
RETURN_FALSE;
}
@@ -852,8 +877,9 @@
zval *id;
xmlNode *nodep;
dom_object *intern;
- char *name, *value;
+ char *name;
int name_len;
+ xmlAttrPtr attr;
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
"Os", &id, dom_element_class_entry, &name, &name_len) == FAILURE) {
return;
@@ -861,11 +887,10 @@
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
- value = xmlGetProp(nodep, name);
- if (value == NULL) {
+ attr = dom_get_dom1_attribute(nodep, (xmlChar *)name);
+ if (attr == NULL) {
RETURN_FALSE;
} else {
- xmlFree(value);
RETURN_TRUE;
}
}
http://cvs.php.net/viewvc.cgi/php-src/ext/dom/tests/bug38474.phpt?view=markup&rev=1.1
Index: php-src/ext/dom/tests/bug38474.phpt
+++ php-src/ext/dom/tests/bug38474.phpt
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php