-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-12870: Creating an xmlns attribute results in a DOMException #12888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.