Skip to content

Commit 106d844

Browse files
committed
Address review comments and split tests
1 parent 73a1e48 commit 106d844

7 files changed

+165
-83
lines changed

ext/dom/document.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ PHP_METHOD(DOMDocument, createAttributeNS)
911911
if (nodep != NULL && uri_len > 0) {
912912
nsptr = xmlSearchNsByHref(nodep->doc, root, (xmlChar *) uri);
913913
if (nsptr == NULL || nsptr->prefix == NULL) {
914-
nsptr = dom_get_ns(root, uri, &errorcode, prefix);
914+
nsptr = dom_get_ns(root, uri, &errorcode, prefix ? prefix : "default");
915915
}
916916
xmlSetNs(nodep, nsptr);
917917
}

ext/dom/tests/DOMDocument_createAttributeNS_prefix_conflict.phpt

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNodeNS variation, with prefix
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument();
9+
$doc->appendChild($doc->createElement('container'));
10+
11+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns1', 'foo:hello'))?->namespaceURI);
12+
echo $doc->saveXML(), "\n";
13+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns2', 'foo:hello'))?->namespaceURI);
14+
echo $doc->saveXML(), "\n";
15+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns3', 'foo:hello'))?->namespaceURI);
16+
echo $doc->saveXML(), "\n";
17+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns4', 'foo:hello'))?->namespaceURI);
18+
echo $doc->saveXML(), "\n";
19+
20+
?>
21+
--EXPECT--
22+
NULL
23+
<?xml version="1.0"?>
24+
<container xmlns:foo="http://php.net/ns1" foo:hello=""/>
25+
26+
NULL
27+
<?xml version="1.0"?>
28+
<container xmlns:foo="http://php.net/ns1" xmlns:default="http://php.net/ns2" foo:hello="" default:hello=""/>
29+
30+
NULL
31+
<?xml version="1.0"?>
32+
<container xmlns:foo="http://php.net/ns1" xmlns:default="http://php.net/ns2" xmlns:default1="http://php.net/ns3" foo:hello="" default:hello="" default1:hello=""/>
33+
34+
NULL
35+
<?xml version="1.0"?>
36+
<container xmlns:foo="http://php.net/ns1" xmlns:default="http://php.net/ns2" xmlns:default1="http://php.net/ns3" xmlns:default2="http://php.net/ns4" foo:hello="" default:hello="" default1:hello="" default2:hello=""/>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNodeNS variation, without prefix
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument();
9+
$doc->appendChild($doc->createElement('container'));
10+
11+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns1', 'hello'))?->namespaceURI);
12+
echo $doc->saveXML(), "\n";
13+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns2', 'hello'))?->namespaceURI);
14+
echo $doc->saveXML(), "\n";
15+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns3', 'hello'))?->namespaceURI);
16+
echo $doc->saveXML(), "\n";
17+
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns4', 'hello'))?->namespaceURI);
18+
echo $doc->saveXML(), "\n";
19+
20+
?>
21+
--EXPECT--
22+
NULL
23+
<?xml version="1.0"?>
24+
<container xmlns:default="http://php.net/ns1" default:hello=""/>
25+
26+
NULL
27+
<?xml version="1.0"?>
28+
<container xmlns:default="http://php.net/ns1" xmlns:default1="http://php.net/ns2" default:hello="" default1:hello=""/>
29+
30+
NULL
31+
<?xml version="1.0"?>
32+
<container xmlns:default="http://php.net/ns1" xmlns:default1="http://php.net/ns2" xmlns:default2="http://php.net/ns3" default:hello="" default1:hello="" default2:hello=""/>
33+
34+
NULL
35+
<?xml version="1.0"?>
36+
<container xmlns:default="http://php.net/ns1" xmlns:default1="http://php.net/ns2" xmlns:default2="http://php.net/ns3" xmlns:default3="http://php.net/ns4" default:hello="" default1:hello="" default2:hello="" default3:hello=""/>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNode variation (DOM Level 3), mixed
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument();
9+
$doc->appendChild($doc->createElement('container'));
10+
11+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns1', 'foo:hello'))?->namespaceURI);
12+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns1', 'hello'))?->namespaceURI);
13+
echo $doc->saveXML(), "\n";
14+
15+
?>
16+
--EXPECT--
17+
NULL
18+
string(18) "http://php.net/ns1"
19+
<?xml version="1.0"?>
20+
<container xmlns:foo="http://php.net/ns1" foo:hello=""/>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNode variation (DOM Level 3), with prefix
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument();
9+
$doc->appendChild($doc->createElement('container'));
10+
11+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns1', 'foo:hello'))?->namespaceURI);
12+
echo $doc->saveXML(), "\n";
13+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns2', 'foo:hello'))?->namespaceURI);
14+
echo $doc->saveXML(), "\n";
15+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns3', 'foo:hello'))?->namespaceURI);
16+
echo $doc->saveXML(), "\n";
17+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns4', 'foo:hello'))?->namespaceURI);
18+
echo $doc->saveXML(), "\n";
19+
20+
?>
21+
--EXPECT--
22+
NULL
23+
<?xml version="1.0"?>
24+
<container xmlns:foo="http://php.net/ns1" foo:hello=""/>
25+
26+
string(18) "http://php.net/ns1"
27+
<?xml version="1.0"?>
28+
<container xmlns:foo="http://php.net/ns1" xmlns:default="http://php.net/ns2" default:hello=""/>
29+
30+
string(18) "http://php.net/ns2"
31+
<?xml version="1.0"?>
32+
<container xmlns:foo="http://php.net/ns1" xmlns:default="http://php.net/ns2" xmlns:default1="http://php.net/ns3" default1:hello=""/>
33+
34+
string(18) "http://php.net/ns3"
35+
<?xml version="1.0"?>
36+
<container xmlns:foo="http://php.net/ns1" xmlns:default="http://php.net/ns2" xmlns:default1="http://php.net/ns3" xmlns:default2="http://php.net/ns4" default2:hello=""/>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNode variation (DOM Level 3), without prefix
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = new DOMDocument();
9+
$doc->appendChild($doc->createElement('container'));
10+
11+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns1', 'hello'))?->namespaceURI);
12+
echo $doc->saveXML(), "\n";
13+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns2', 'hello'))?->namespaceURI);
14+
echo $doc->saveXML(), "\n";
15+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns3', 'hello'))?->namespaceURI);
16+
echo $doc->saveXML(), "\n";
17+
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns4', 'hello'))?->namespaceURI);
18+
echo $doc->saveXML(), "\n";
19+
20+
?>
21+
--EXPECT--
22+
NULL
23+
<?xml version="1.0"?>
24+
<container xmlns:default="http://php.net/ns1" default:hello=""/>
25+
26+
string(18) "http://php.net/ns1"
27+
<?xml version="1.0"?>
28+
<container xmlns:default="http://php.net/ns1" xmlns:default1="http://php.net/ns2" default1:hello=""/>
29+
30+
string(18) "http://php.net/ns2"
31+
<?xml version="1.0"?>
32+
<container xmlns:default="http://php.net/ns1" xmlns:default1="http://php.net/ns2" xmlns:default2="http://php.net/ns3" default2:hello=""/>
33+
34+
string(18) "http://php.net/ns3"
35+
<?xml version="1.0"?>
36+
<container xmlns:default="http://php.net/ns1" xmlns:default1="http://php.net/ns2" xmlns:default2="http://php.net/ns3" xmlns:default3="http://php.net/ns4" default3:hello=""/>

0 commit comments

Comments
 (0)