-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix various namespace prefix conflict resolution bugs #11777
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
5 commits
Select commit
Hold shift + click to select a range
6f08cda
Add regression tests
nielsdos 8965426
Fix various namespace prefix conflict resolution bugs
nielsdos 12c1447
Address review comments and split tests
nielsdos f61b77f
Modify test to workaround bug 80927
nielsdos 650917e
Restore test to original
nielsdos 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
65 changes: 65 additions & 0 deletions
65
ext/dom/tests/DOMDocument_importNode_attribute_prefix_conflict.phpt
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,65 @@ | ||
--TEST-- | ||
DOMDocument::importNode() with attribute prefix name conflict | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
echo "--- Non-default namespace test case without a default namespace in the destination ---\n"; | ||
|
||
$dom1 = new DOMDocument(); | ||
$dom2 = new DOMDocument(); | ||
$dom1->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net" foo:bar="yes"/>'); | ||
$dom2->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net/2"/>'); | ||
$attribute = $dom1->documentElement->getAttributeNode('foo:bar'); | ||
$imported = $dom2->importNode($attribute); | ||
$dom2->documentElement->setAttributeNodeNS($imported); | ||
|
||
echo $dom1->saveXML(); | ||
echo $dom2->saveXML(); | ||
|
||
echo "--- Non-default namespace test case with a default namespace in the destination ---\n"; | ||
|
||
$dom1 = new DOMDocument(); | ||
$dom2 = new DOMDocument(); | ||
$dom1->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net" foo:bar="yes"/>'); | ||
$dom2->loadXML('<?xml version="1.0"?><container xmlns="http://php.net" xmlns:foo="http://php.net/2"/>'); | ||
$attribute = $dom1->documentElement->getAttributeNode('foo:bar'); | ||
$imported = $dom2->importNode($attribute); | ||
$dom2->documentElement->setAttributeNodeNS($imported); | ||
|
||
echo $dom1->saveXML(); | ||
echo $dom2->saveXML(); | ||
|
||
echo "--- Default namespace test case ---\n"; | ||
|
||
// We don't expect the namespace to be imported because default namespaces on the same element don't apply to attributes | ||
// but the attribute should be imported | ||
$dom1 = new DOMDocument(); | ||
$dom2 = new DOMDocument(); | ||
$dom1->loadXML('<?xml version="1.0"?><container xmlns="http://php.net" bar="yes"/>'); | ||
$dom2->loadXML('<?xml version="1.0"?><container xmlns="http://php.net/2"/>'); | ||
$attribute = $dom1->documentElement->getAttributeNode('bar'); | ||
$imported = $dom2->importNode($attribute); | ||
$dom2->documentElement->setAttributeNodeNS($imported); | ||
|
||
echo $dom1->saveXML(); | ||
echo $dom2->saveXML(); | ||
|
||
?> | ||
--EXPECT-- | ||
--- Non-default namespace test case without a default namespace in the destination --- | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net" foo:bar="yes"/> | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net/2" xmlns:default="http://php.net" default:bar="yes"/> | ||
--- Non-default namespace test case with a default namespace in the destination --- | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net" foo:bar="yes"/> | ||
<?xml version="1.0"?> | ||
<container xmlns="http://php.net" xmlns:foo="http://php.net/2" xmlns:default="http://php.net" default:bar="yes"/> | ||
--- Default namespace test case --- | ||
<?xml version="1.0"?> | ||
<container xmlns="http://php.net" bar="yes"/> | ||
<?xml version="1.0"?> | ||
<container xmlns="http://php.net/2" bar="yes"/> |
35 changes: 35 additions & 0 deletions
35
ext/dom/tests/DOMElement_setAttributeNS_prefix_conflict.phpt
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,35 @@ | ||
--TEST-- | ||
DOMElement::setAttributeNS() with prefix name conflict | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
echo "--- Non-default namespace test case ---\n"; | ||
|
||
$dom = new DOMDocument(); | ||
$dom->loadXML('<?xml version="1.0"?><container xmlns:foo="http://php.net" foo:bar="yes"/>'); | ||
$dom->documentElement->setAttributeNS('http://php.net/2', 'foo:bar', 'no1'); | ||
echo $dom->saveXML(); | ||
$dom->documentElement->setAttributeNS('http://php.net/2', 'bar', 'no2'); | ||
echo $dom->saveXML(); | ||
|
||
echo "--- Default namespace test case ---\n"; | ||
|
||
$dom = new DOMDocument(); | ||
$dom->loadXML('<?xml version="1.0"?><container xmlns="http://php.net" bar="yes"/>'); | ||
$dom->documentElement->setAttributeNS('http://php.net/2', 'bar', 'no1'); | ||
echo $dom->saveXML(); | ||
$dom->documentElement->setAttributeNS('http://php.net/2', 'bar', 'no2'); | ||
echo $dom->saveXML(); | ||
?> | ||
--EXPECT-- | ||
--- Non-default namespace test case --- | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net" xmlns:default="http://php.net/2" foo:bar="yes" default:bar="no1"/> | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net" xmlns:default="http://php.net/2" foo:bar="yes" default:bar="no2"/> | ||
--- Default namespace test case --- | ||
<?xml version="1.0"?> | ||
<container xmlns="http://php.net" xmlns:default="http://php.net/2" bar="yes" default:bar="no1"/> | ||
<?xml version="1.0"?> | ||
<container xmlns="http://php.net" xmlns:default="http://php.net/2" bar="yes" default:bar="no2"/> |
36 changes: 36 additions & 0 deletions
36
ext/dom/tests/createAttributeNS_prefix_conflicts/setAttributeNS_with_prefix.phpt
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,36 @@ | ||
--TEST-- | ||
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNodeNS variation, with prefix | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
$doc = new DOMDocument(); | ||
$doc->appendChild($doc->createElement('container')); | ||
|
||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns1', 'foo:hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns2', 'foo:hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns3', 'foo:hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns4', 'foo:hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
NULL | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net/ns1" foo:hello=""/> | ||
|
||
NULL | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net/ns1" xmlns:default="http://php.net/ns2" foo:hello="" default:hello=""/> | ||
|
||
NULL | ||
<?xml version="1.0"?> | ||
<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=""/> | ||
|
||
NULL | ||
<?xml version="1.0"?> | ||
<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=""/> |
36 changes: 36 additions & 0 deletions
36
ext/dom/tests/createAttributeNS_prefix_conflicts/setAttributeNS_without_prefix.phpt
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,36 @@ | ||
--TEST-- | ||
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNodeNS variation, without prefix | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
$doc = new DOMDocument(); | ||
$doc->appendChild($doc->createElement('container')); | ||
|
||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns1', 'hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns2', 'hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns3', 'hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
var_dump($doc->documentElement->setAttributeNodeNS($doc->createAttributeNS('http://php.net/ns4', 'hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
NULL | ||
<?xml version="1.0"?> | ||
<container xmlns:default="http://php.net/ns1" default:hello=""/> | ||
|
||
NULL | ||
<?xml version="1.0"?> | ||
<container xmlns:default="http://php.net/ns1" xmlns:default1="http://php.net/ns2" default:hello="" default1:hello=""/> | ||
|
||
NULL | ||
<?xml version="1.0"?> | ||
<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=""/> | ||
|
||
NULL | ||
<?xml version="1.0"?> | ||
<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=""/> |
20 changes: 20 additions & 0 deletions
20
ext/dom/tests/createAttributeNS_prefix_conflicts/setAttribute_mixed_prefix.phpt
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,20 @@ | ||
--TEST-- | ||
DOMDocument::createAttributeNS() with prefix name conflict - setAttributeNode variation (DOM Level 3), mixed | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
$doc = new DOMDocument(); | ||
$doc->appendChild($doc->createElement('container')); | ||
|
||
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns1', 'foo:hello'))?->namespaceURI); | ||
var_dump($doc->documentElement->setAttributeNode($doc->createAttributeNS('http://php.net/ns1', 'hello'))?->namespaceURI); | ||
echo $doc->saveXML(), "\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
NULL | ||
string(18) "http://php.net/ns1" | ||
<?xml version="1.0"?> | ||
<container xmlns:foo="http://php.net/ns1" foo:hello=""/> |
Oops, something went wrong.
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.