summaryrefslogtreecommitdiff
path: root/ext/simplexml
diff options
context:
space:
mode:
authorRob Richards <rrichards@php.net>2007-11-12 18:59:26 +0000
committerRob Richards <rrichards@php.net>2007-11-12 18:59:26 +0000
commit376d5f828d1e03177afab68cec8b4bc5c0da94d7 (patch)
treeefce46e2178a30cfef6ea6c43c67a59c9e33968a /ext/simplexml
parent5d09ce66a3994e3e68852e7d44bce2af3493ef78 (diff)
downloadphp-git-376d5f828d1e03177afab68cec8b4bc5c0da94d7.tar.gz
MFH: fix bug #43221 (SimpleXML adding default namespace in addAttribute)
add test
Diffstat (limited to 'ext/simplexml')
-rw-r--r--ext/simplexml/simplexml.c7
-rw-r--r--ext/simplexml/tests/bug43221.phpt15
2 files changed, 22 insertions, 0 deletions
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index c97bfafc72..297cf11a66 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -1635,6 +1635,13 @@ SXE_METHOD(addAttribute)
localname = xmlSplitQName2((xmlChar *)qname, &prefix);
if (localname == NULL) {
+ if (nsuri_len > 0) {
+ if (prefix != NULL) {
+ xmlFree(prefix);
+ }
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute requires prefix for namespace");
+ return;
+ }
localname = xmlStrdup((xmlChar *)qname);
}
diff --git a/ext/simplexml/tests/bug43221.phpt b/ext/simplexml/tests/bug43221.phpt
new file mode 100644
index 0000000000..6973d091c7
--- /dev/null
+++ b/ext/simplexml/tests/bug43221.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #43221 (SimpleXML adding default namespace in addAttribute)
+--FILE--
+<?php
+$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><root />');
+$n = $xml->addChild("node", "value");
+$n->addAttribute("a", "b");
+$n->addAttribute("c", "d", "http://bar.com");
+$n->addAttribute("foo:e", "f", "http://bar.com");
+print_r($xml->asXml());
+?>
+--EXPECTF--
+Warning: SimpleXMLElement::addAttribute(): Attribute requires prefix for namespace in %sbug43221.php on line %d
+<?xml version="1.0" encoding="utf-8"?>
+<root><node xmlns:foo="http://bar.com" a="b" foo:e="f">value</node></root> \ No newline at end of file