-
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.
Implement request #30622: make $namespace parameter functional
This parameter never actually did anything and was forgotten about. We solve this by detecting when we have a $namespace argument (that won't conflict with the name argument) and creating a Clark notation name out of it. Closes GH-16123.
- Loading branch information
Showing
5 changed files
with
218 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--TEST-- | ||
Request #30622 (XSLT: xsltProcessor->setParameter() cannot set namespace URI) | ||
--EXTENSIONS-- | ||
xsl | ||
--CREDITS-- | ||
Based on a test by <ishikawa at arielworks dot com> | ||
--FILE-- | ||
<?php | ||
|
||
$xmlDom = new DOMDocument(); | ||
$xmlDom->loadXML('<root/>'); | ||
|
||
$xslDom = new DOMDocument(); | ||
$xslDom->loadXML(<<<'XML' | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:test="http://www.php.net/test"> | ||
<xsl:param name="foo" select="'EMPTY'"/> | ||
<xsl:param name="test:foo" select="'EMPTY'"/> | ||
<xsl:template match="/root"> | ||
<xsl:text>Namespace "NULL": </xsl:text> | ||
<xsl:value-of select="$foo"/> | ||
<xsl:text>, Namespace "http://www.php.net/test": </xsl:text> | ||
<xsl:value-of select="$test:foo"/> | ||
</xsl:template> | ||
</xsl:stylesheet> | ||
XML); | ||
|
||
$proc = new XSLTProcessor(); | ||
$proc->importStyleSheet($xslDom); | ||
|
||
echo "--- Set both empty and non-empty namespace ---\n"; | ||
|
||
$proc->setParameter("", "foo", "SET1"); | ||
$proc->setParameter("http://www.php.net/test", "foo", "SET2"); | ||
var_dump($proc->getParameter("", "foo")); | ||
var_dump($proc->getParameter("http://www.php.net/test", "foo")); | ||
|
||
print $proc->transformToXML($xmlDom); | ||
|
||
echo "--- Remove empty namespace entry ---\n"; | ||
|
||
var_dump($proc->removeParameter("", "foo")); | ||
var_dump($proc->getParameter("", "foo")); | ||
var_dump($proc->getParameter("http://www.php.net/test", "foo")); | ||
|
||
print $proc->transformToXML($xmlDom); | ||
|
||
echo "--- Remove non-empty namespace entry ---\n"; | ||
|
||
var_dump($proc->removeParameter("http://www.php.net/test", "foo")); | ||
var_dump($proc->getParameter("", "foo")); | ||
var_dump($proc->getParameter("http://www.php.net/test", "foo")); | ||
|
||
print $proc->transformToXML($xmlDom); | ||
|
||
echo "--- Set via array ---\n"; | ||
|
||
$proc->setParameter("", ["foo" => "SET1"]); | ||
$proc->setParameter("http://www.php.net/test", ["foo" => "SET2"]); | ||
|
||
print $proc->transformToXML($xmlDom); | ||
|
||
?> | ||
--EXPECT-- | ||
--- Set both empty and non-empty namespace --- | ||
string(4) "SET1" | ||
string(4) "SET2" | ||
<?xml version="1.0"?> | ||
Namespace "NULL": SET1, Namespace "http://www.php.net/test": SET2 | ||
--- Remove empty namespace entry --- | ||
bool(true) | ||
bool(false) | ||
string(4) "SET2" | ||
<?xml version="1.0"?> | ||
Namespace "NULL": EMPTY, Namespace "http://www.php.net/test": SET2 | ||
--- Remove non-empty namespace entry --- | ||
bool(true) | ||
bool(false) | ||
bool(false) | ||
<?xml version="1.0"?> | ||
Namespace "NULL": EMPTY, Namespace "http://www.php.net/test": EMPTY | ||
--- Set via array --- | ||
<?xml version="1.0"?> | ||
Namespace "NULL": SET1, Namespace "http://www.php.net/test": SET2 |
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,59 @@ | ||
--TEST-- | ||
Request #30622 (XSLT: xsltProcessor->setParameter() cannot set namespace URI) - error cases | ||
--EXTENSIONS-- | ||
xsl | ||
--CREDITS-- | ||
Based on a test by <ishikawa at arielworks dot com> | ||
--FILE-- | ||
<?php | ||
|
||
$proc = new XSLTProcessor(); | ||
|
||
try { | ||
$proc->setParameter("urn:x", "{urn:a}x", ""); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$proc->setParameter("urn:x", "a:b", ""); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$proc->getParameter("urn:x", "{urn:a}x"); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$proc->getParameter("urn:x", "a:b"); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$proc->removeParameter("urn:x", "{urn:a}x"); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$proc->removeParameter("urn:x", "a:b"); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
// Edge cases, should work | ||
$proc->setParameter("urn:x", ":b", ""); | ||
$proc->setParameter("urn:x", ":", ""); | ||
|
||
?> | ||
--EXPECT-- | ||
XSLTProcessor::setParameter(): Argument #2 ($name) must not use clark notation when argument #1 ($namespace) is not empty | ||
XSLTProcessor::setParameter(): Argument #2 ($name) must not be a QName when argument #1 ($namespace) is not empty | ||
XSLTProcessor::getParameter(): Argument #2 ($name) must not use clark notation when argument #1 ($namespace) is not empty | ||
XSLTProcessor::getParameter(): Argument #2 ($name) must not be a QName when argument #1 ($namespace) is not empty | ||
XSLTProcessor::removeParameter(): Argument #2 ($name) must not use clark notation when argument #1 ($namespace) is not empty | ||
XSLTProcessor::removeParameter(): Argument #2 ($name) must not be a QName when argument #1 ($namespace) is not empty |
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