]> granicus.if.org Git - php/commitdiff
- Fix issue with entities in attributes
authorMarcus Boerger <helly@php.net>
Mon, 24 Oct 2005 08:29:36 +0000 (08:29 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 24 Oct 2005 08:29:36 +0000 (08:29 +0000)
ext/simplexml/simplexml.c
ext/simplexml/tests/023.phpt [new file with mode: 0755]

index e42ab2484e066d90990984b11d9dbb16ae2fc3d3..19bb0fadec24af7b4aa4dd7b694c9de8f112585a 100644 (file)
@@ -689,10 +689,15 @@ sxe_properties_get(zval *object TSRMLS_DC)
 
        GET_NODE(sxe, node);
        node = php_sxe_get_first_node(sxe, node TSRMLS_CC);
-
-       if (node) {
-               node = node->children;
-
+       if (node && sxe->iter.type != SXE_ITER_ATTRLIST) {
+               if (node->type == XML_ATTRIBUTE_NODE) {
+                       MAKE_STD_ZVAL(value);
+                       ZVAL_STRING(value, xmlNodeListGetString(node->doc, node->children, 1), 1);
+                       zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
+                       node = NULL;
+               } else {
+                       node = node->children;
+               }
                while (node) {
                        if (node->children != NULL || node->prev != NULL || node->next != NULL) {
                                SKIP_TEXT(node);
diff --git a/ext/simplexml/tests/023.phpt b/ext/simplexml/tests/023.phpt
new file mode 100755 (executable)
index 0000000..dd6dde5
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+SimpleXML: Attributes with entities
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip"; ?>
+--FILE--
+<?php 
+
+$xml =<<<EOF
+<?xml version='1.0'?>
+<!DOCTYPE talks SYSTEM "nbsp.dtd" [
+<!ELEMENT root  EMPTY>
+<!ATTLIST root  attr1 CDATA #IMPLIED>
+<!ENTITY  nbsp   "&#38;#x00A0;">
+]>
+<root attr='foo&nbsp;bar&nbsp;baz'></root>
+EOF;
+
+$sxe = simplexml_load_string($xml);
+
+var_dump($sxe);
+var_dump($sxe['attr']);
+?>
+===DONE===
+--EXPECTF--
+object(SimpleXMLElement)#%d (0) {
+}
+object(SimpleXMLElement)#%d (1) {
+  [0]=>
+  string(%d) "foo%sbar%sbaz"
+}
+===DONE===