-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GH-12870: Creating an xmlns attribute results in a DOMException
There were multiple things here since forever, see the GH thread [1] for discussion. There were already many fixes to this function previously, and as a consequence of one of those fixes this started throwing exceptions for a correct use-case. It turns out that even when reverting to the previous behaviour there are still bugs. Just fix all of them while we have the chance. [1] #12870 Closes GH-12888.
- Loading branch information
Showing
6 changed files
with
239 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
function test(?string $uri, string $qualifiedName) { | ||
$uri_readable = is_null($uri) ? 'NULL' : "\"$uri\""; | ||
echo "--- Testing $uri_readable, \"$qualifiedName\" ---\n"; | ||
$d = new DOMDocument(); | ||
$d->appendChild($d->createElement('root')); | ||
try { | ||
$attr = $d->createAttributeNS($uri, $qualifiedName); | ||
$d->documentElement->setAttributeNodeNS($attr); | ||
echo "Attr prefix: "; | ||
var_dump($attr->prefix); | ||
echo "Attr namespaceURI: "; | ||
var_dump($attr->namespaceURI); | ||
echo "Attr value: "; | ||
var_dump($attr->value); | ||
echo "root namespaceURI: "; | ||
var_dump($d->documentElement->namespaceURI); | ||
echo "Equality check: "; | ||
$parts = explode(':', $qualifiedName); | ||
var_dump($attr === $d->documentElement->getAttributeNodeNS($uri, $parts[count($parts) - 1])); | ||
echo $d->saveXML(), "\n"; | ||
} catch (DOMException $e) { | ||
echo "Exception: ", $e->getMessage(), "\n\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--TEST-- | ||
GH-12870 (Creating an xmlns attribute results in a DOMException) - xmlns variations | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
require __DIR__ . '/gh12870.inc'; | ||
|
||
echo "=== NORMAL CASES ===\n"; | ||
|
||
test('http://www.w3.org/2000/xmlns/qx', 'foo:xmlns'); | ||
test('http://www.w3.org/2000/xmlns/', 'xmlns'); | ||
test('http://www.w3.org/2000/xmlns/', 'xmlns:xmlns'); | ||
|
||
echo "=== ERROR CASES ===\n"; | ||
|
||
test('http://www.w3.org/2000/xmlns/', 'bar:xmlns'); | ||
test('http://www.w3.org/2000/xmlns/a', 'xmlns'); | ||
test('http://www.w3.org/2000/xmlns/a', 'xmlns:bar'); | ||
test(null, 'xmlns:bar'); | ||
test('', 'xmlns'); | ||
test('http://www.w3.org/2000/xmlns/', ''); | ||
|
||
?> | ||
--EXPECT-- | ||
=== NORMAL CASES === | ||
--- Testing "http://www.w3.org/2000/xmlns/qx", "foo:xmlns" --- | ||
Attr prefix: string(3) "foo" | ||
Attr namespaceURI: string(31) "http://www.w3.org/2000/xmlns/qx" | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(true) | ||
<?xml version="1.0"?> | ||
<root xmlns:foo="http://www.w3.org/2000/xmlns/qx" foo:xmlns=""/> | ||
|
||
--- Testing "http://www.w3.org/2000/xmlns/", "xmlns" --- | ||
Attr prefix: string(0) "" | ||
Attr namespaceURI: string(29) "http://www.w3.org/2000/xmlns/" | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(true) | ||
<?xml version="1.0"?> | ||
<root xmlns=""/> | ||
|
||
--- Testing "http://www.w3.org/2000/xmlns/", "xmlns:xmlns" --- | ||
Attr prefix: string(5) "xmlns" | ||
Attr namespaceURI: string(29) "http://www.w3.org/2000/xmlns/" | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(true) | ||
<?xml version="1.0"?> | ||
<root xmlns:xmlns="http://www.w3.org/2000/xmlns/" xmlns:xmlns=""/> | ||
|
||
=== ERROR CASES === | ||
--- Testing "http://www.w3.org/2000/xmlns/", "bar:xmlns" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing "http://www.w3.org/2000/xmlns/a", "xmlns" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing "http://www.w3.org/2000/xmlns/a", "xmlns:bar" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing NULL, "xmlns:bar" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing "", "xmlns" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing "http://www.w3.org/2000/xmlns/", "" --- | ||
Exception: Namespace Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--TEST-- | ||
GH-12870 (Creating an xmlns attribute results in a DOMException) - xml variations | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
require __DIR__ . '/gh12870.inc'; | ||
|
||
echo "=== NORMAL CASES ===\n"; | ||
|
||
test('http://www.w3.org/XML/1998/namespaceqx', 'foo:xml'); | ||
test('http://www.w3.org/XML/1998/namespace', 'xml'); | ||
test('http://www.w3.org/XML/1998/namespace', 'bar:xml'); | ||
test('', 'xml'); | ||
test('http://www.w3.org/XML/1998/namespacea', 'xml'); | ||
|
||
echo "=== ERROR CASES ===\n"; | ||
|
||
test('http://www.w3.org/XML/1998/namespace', 'xmlns:xml'); | ||
test('http://www.w3.org/XML/1998/namespace', ''); | ||
test('http://www.w3.org/XML/1998/namespacea', 'xml:foo'); | ||
test(NULL, 'xml:foo'); | ||
|
||
?> | ||
--EXPECT-- | ||
=== NORMAL CASES === | ||
--- Testing "http://www.w3.org/XML/1998/namespaceqx", "foo:xml" --- | ||
Attr prefix: string(3) "foo" | ||
Attr namespaceURI: string(38) "http://www.w3.org/XML/1998/namespaceqx" | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(true) | ||
<?xml version="1.0"?> | ||
<root xmlns:foo="http://www.w3.org/XML/1998/namespaceqx" foo:xml=""/> | ||
|
||
--- Testing "http://www.w3.org/XML/1998/namespace", "xml" --- | ||
Attr prefix: string(3) "xml" | ||
Attr namespaceURI: string(36) "http://www.w3.org/XML/1998/namespace" | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(true) | ||
<?xml version="1.0"?> | ||
<root xml:xml=""/> | ||
|
||
--- Testing "http://www.w3.org/XML/1998/namespace", "bar:xml" --- | ||
Attr prefix: string(3) "xml" | ||
Attr namespaceURI: string(36) "http://www.w3.org/XML/1998/namespace" | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(true) | ||
<?xml version="1.0"?> | ||
<root xml:xml=""/> | ||
|
||
--- Testing "", "xml" --- | ||
Attr prefix: string(0) "" | ||
Attr namespaceURI: NULL | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(false) | ||
<?xml version="1.0"?> | ||
<root xml=""/> | ||
|
||
--- Testing "http://www.w3.org/XML/1998/namespacea", "xml" --- | ||
Attr prefix: string(7) "default" | ||
Attr namespaceURI: string(37) "http://www.w3.org/XML/1998/namespacea" | ||
Attr value: string(0) "" | ||
root namespaceURI: NULL | ||
Equality check: bool(true) | ||
<?xml version="1.0"?> | ||
<root xmlns:default="http://www.w3.org/XML/1998/namespacea" default:xml=""/> | ||
|
||
=== ERROR CASES === | ||
--- Testing "http://www.w3.org/XML/1998/namespace", "xmlns:xml" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing "http://www.w3.org/XML/1998/namespace", "" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing "http://www.w3.org/XML/1998/namespacea", "xml:foo" --- | ||
Exception: Namespace Error | ||
|
||
--- Testing NULL, "xml:foo" --- | ||
Exception: Namespace Error |