-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Request #64137: XSLTProcessor::setParameter() should allow both quotes to be used #12331
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
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--TEST-- | ||
Request #64137 (XSLTProcessor::setParameter() should allow both quotes to be used) | ||
--EXTENSIONS-- | ||
xsl | ||
--FILE-- | ||
<?php | ||
|
||
function test(string $input) { | ||
$xml = new DOMDocument; | ||
$xml->loadXML('<X/>'); | ||
|
||
$xsl = new DOMDocument; | ||
$xsl->loadXML('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="text"/><xsl:param name="foo"/><xsl:template match="/"><xsl:value-of select="$foo"/></xsl:template></xsl:stylesheet>'); | ||
|
||
$xslt = new XSLTProcessor; | ||
$xslt->importStylesheet($xsl); | ||
$xslt->setParameter('', 'foo', $input); | ||
|
||
echo $xslt->transformToXml($xml), "\n"; | ||
} | ||
|
||
test(""); | ||
test("a'"); | ||
test("a\""); | ||
test("fo'o\"ba'r\"ba'z"); | ||
test("\"\"\"fo'o\"ba'r\"ba'z\"\"\""); | ||
test("'''\"\"\"fo'o\"ba'r\"ba'z\"\"\"'''"); | ||
|
||
?> | ||
--EXPECT-- | ||
a' | ||
a" | ||
fo'o"ba'r"ba'z | ||
"""fo'o"ba'r"ba'z""" | ||
'''"""fo'o"ba'r"ba'z"""''' |
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,102 @@ | ||
--TEST-- | ||
setParameter exceptions test | ||
--EXTENSIONS-- | ||
xsl | ||
--FILE-- | ||
<?php | ||
|
||
function test(array $options) { | ||
$xml = new DOMDocument; | ||
$xml->loadXML('<X/>'); | ||
|
||
$xsl = new DOMDocument; | ||
$xsl->loadXML('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="text"/><xsl:param name="foo"/><xsl:template match="/"><xsl:value-of select="$foo"/></xsl:template></xsl:stylesheet>'); | ||
|
||
$xslt = new XSLTProcessor; | ||
$xslt->importStylesheet($xsl); | ||
$xslt->setParameter('', $options); | ||
|
||
echo $xslt->transformToXml($xml), "\n"; | ||
} | ||
|
||
echo "--- Invalid key ---\n"; | ||
|
||
try { | ||
test([ | ||
12345 => "foo" | ||
]); | ||
} catch (TypeError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
echo "--- Valid key and value, but special cases ---\n"; | ||
|
||
test([ | ||
"foo" => null, | ||
]); | ||
|
||
test([ | ||
"foo" => true, | ||
]); | ||
|
||
echo "--- Exception from Stringable should abort execution ---\n"; | ||
|
||
class MyStringable { | ||
public function __toString(): string { | ||
throw new Exception("exception!"); | ||
} | ||
} | ||
|
||
try { | ||
test([ | ||
"foo" => new MyStringable, | ||
]); | ||
} catch (Throwable $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
echo "--- Exception from warning should abort execution ---\n"; | ||
|
||
set_error_handler(function($errno, $errstr) { | ||
throw new Exception($errstr); | ||
}, E_WARNING); | ||
|
||
try { | ||
test([ | ||
"foo" => [], | ||
"foo2" => [], | ||
]); | ||
} catch (Throwable $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
set_error_handler(null, E_WARNING); | ||
|
||
echo "--- Warning may continue execution ---\n"; | ||
|
||
try { | ||
test([ | ||
"foo" => [], | ||
"foo2" => [], | ||
]); | ||
} catch (Throwable $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
--- Invalid key --- | ||
XSLTProcessor::setParameter(): Argument #2 ($name) must contain only string keys | ||
--- Valid key and value, but special cases --- | ||
|
||
1 | ||
--- Exception from Stringable should abort execution --- | ||
exception! | ||
--- Exception from warning should abort execution --- | ||
Array to string conversion | ||
--- Warning may continue execution --- | ||
|
||
Warning: Array to string conversion in %s on line %d | ||
|
||
Warning: Array to string conversion in %s on line %d | ||
Array |
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,43 @@ | ||
--TEST-- | ||
setParameter() with null bytes | ||
--EXTENSIONS-- | ||
xsl | ||
--FILE-- | ||
<?php | ||
|
||
$xslt = new XSLTProcessor(); | ||
|
||
try { | ||
$xslt->setParameter("", "foo\0", "bar"); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$xslt->setParameter("", "foo", "bar\0"); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$xslt->setParameter("", [ | ||
"foo\0" => "bar", | ||
]); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
$xslt->setParameter("", [ | ||
"foo" => "bar\0", | ||
]); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
XSLTProcessor::setParameter(): Argument #2 ($name) must not contain any null bytes | ||
XSLTProcessor::setParameter(): Argument #3 ($value) must not contain any null bytes | ||
XSLTProcessor::setParameter(): Argument #3 ($value) must not contain keys with any null bytes | ||
XSLTProcessor::setParameter(): Argument #3 ($value) must not contain values with any null bytes |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be clearer, as I was slightly confused just reading the output