-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix spec compliance error for DOMDocument::getElementsByTagNameNS #11343
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
82 changes: 82 additions & 0 deletions
82
ext/dom/tests/DOMDocument_getElementsByTagNameNS_match_any_namespace.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,82 @@ | ||
--TEST-- | ||
DOMDocument::getElementsByTagNameNS() match any namespace | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
/* Sample document taken from https://www.php.net/manual/en/domdocument.getelementsbytagname.php */ | ||
$xml = <<<EOD | ||
<?xml version="1.0" ?> | ||
<chapter xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
<title>Books of the other guy..</title> | ||
<para> | ||
<xi:include href="book.xml"> | ||
<xi:fallback> | ||
<error>xinclude: book.xml not found</error> | ||
</xi:fallback> | ||
</xi:include> | ||
<include> | ||
This is another namespace | ||
</include> | ||
</para> | ||
</chapter> | ||
EOD; | ||
$dom = new DOMDocument; | ||
|
||
// load the XML string defined above | ||
$dom->loadXML($xml); | ||
|
||
function test($namespace, $local) { | ||
global $dom; | ||
$namespace_str = $namespace !== NULL ? "'$namespace'" : "null"; | ||
echo "-- getElementsByTagNameNS($namespace_str, '$local') --\n"; | ||
foreach ($dom->getElementsByTagNameNS($namespace, $local) as $element) { | ||
echo 'local name: ', $element->localName, ', prefix: ', $element->prefix, "\n"; | ||
} | ||
} | ||
|
||
// Should *also* include objects even without a namespace | ||
test(null, '*'); | ||
// Should *also* include objects even without a namespace | ||
test('*', '*'); | ||
// Should *only* include objects without a namespace | ||
test('', '*'); | ||
// Should *only* include objects with the specified namespace | ||
test('http://www.w3.org/2001/XInclude', '*'); | ||
// Should not give any output | ||
test('', 'fallback'); | ||
// Should not give any output, because the null namespace is the same as the empty namespace | ||
test(null, 'fallback'); | ||
// Should only output the include from the empty namespace | ||
test(null, 'include'); | ||
|
||
?> | ||
--EXPECT-- | ||
-- getElementsByTagNameNS(null, '*') -- | ||
local name: chapter, prefix: | ||
local name: title, prefix: | ||
local name: para, prefix: | ||
local name: error, prefix: | ||
local name: include, prefix: | ||
-- getElementsByTagNameNS('*', '*') -- | ||
local name: chapter, prefix: | ||
local name: title, prefix: | ||
local name: para, prefix: | ||
local name: include, prefix: xi | ||
local name: fallback, prefix: xi | ||
local name: error, prefix: | ||
local name: include, prefix: | ||
-- getElementsByTagNameNS('', '*') -- | ||
local name: chapter, prefix: | ||
local name: title, prefix: | ||
local name: para, prefix: | ||
local name: error, prefix: | ||
local name: include, prefix: | ||
-- getElementsByTagNameNS('http://www.w3.org/2001/XInclude', '*') -- | ||
local name: include, prefix: xi | ||
local name: fallback, prefix: xi | ||
-- getElementsByTagNameNS('', 'fallback') -- | ||
-- getElementsByTagNameNS(null, 'fallback') -- | ||
-- getElementsByTagNameNS(null, 'include') -- | ||
local name: include, prefix: |
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.