Skip to content

Fix empty argument cases for DOMParentNode methods #11768

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ext/dom/characterdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ PHP_METHOD(DOMCharacterData, remove)

PHP_METHOD(DOMCharacterData, after)
{
int argc;
int argc = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those all should be uint32_t in theory, but that's more a master branch thing.

Suggested change
int argc = 0;
uint32_t argc = 0;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that's already done in master :D

zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -381,12 +381,12 @@ PHP_METHOD(DOMCharacterData, after)

PHP_METHOD(DOMCharacterData, before)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -398,12 +398,12 @@ PHP_METHOD(DOMCharacterData, before)

PHP_METHOD(DOMCharacterData, replaceWith)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand Down
8 changes: 4 additions & 4 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2092,12 +2092,12 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocument, append)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -2113,12 +2113,12 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocument, prepend)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand Down
8 changes: 4 additions & 4 deletions ext/dom/documentfragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocumentFragment, append)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -156,12 +156,12 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocumentFragment, prepend)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand Down
20 changes: 10 additions & 10 deletions ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,12 +1137,12 @@ PHP_METHOD(DOMElement, remove)

PHP_METHOD(DOMElement, after)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -1154,12 +1154,12 @@ PHP_METHOD(DOMElement, after)

PHP_METHOD(DOMElement, before)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -1174,12 +1174,12 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMElement, append)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -1195,12 +1195,12 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMElement, prepend)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -1216,12 +1216,12 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMElement, replaceWith)
{
int argc;
int argc = 0;
zval *args, *id;
dom_object *intern;
xmlNode *context;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
RETURN_THROWS();
}

Expand Down
84 changes: 84 additions & 0 deletions ext/dom/tests/DOMParentNode_empty_argument.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--TEST--
DOMParentNode functions with empty argument
--EXTENSIONS--
dom
--FILE--
<?php
$dom = new DOMDocument();
$dom->loadXML('<?xml version="1.0"?><root><node/></root>');

$emptyFragment = $dom->createDocumentFragment();

echo "--- DOMElement test ---\n";

$dom->documentElement->after(...$emptyFragment->childNodes);
$dom->documentElement->before(...$emptyFragment->childNodes);
$dom->documentElement->append(...$emptyFragment->childNodes);
$dom->documentElement->prepend(...$emptyFragment->childNodes);
$dom->documentElement->after();
$dom->documentElement->before();
$dom->documentElement->append();
$dom->documentElement->prepend();
echo $dom->saveXML();

$dom->documentElement->firstChild->replaceWith(...$emptyFragment->childNodes);
echo $dom->saveXML();

$dom->documentElement->replaceWith(...$emptyFragment->childNodes);
echo $dom->saveXML();

echo "--- DOMDocumentFragment test ---\n";

$fragment = $dom->createDocumentFragment();
$fragment->append($dom->createElement('foo'));
$fragment->append(...$emptyFragment->childNodes);
$fragment->prepend(...$emptyFragment->childNodes);
$fragment->append();
$fragment->prepend();
echo $dom->saveXML($fragment), "\n";

echo "--- DOMDocument test ---\n";

$dom->append(...$emptyFragment->childNodes);
$dom->prepend(...$emptyFragment->childNodes);
$dom->append();
$dom->prepend();
echo $dom->saveXML(), "\n";

echo "--- DOMCharacterData test ---\n";

$cdata = $dom->createCDATASection('foo');
$dom->appendChild($cdata);

$cdata->after(...$emptyFragment->childNodes);
$cdata->before(...$emptyFragment->childNodes);
$cdata->after();
$cdata->before();
echo $dom->saveXML(), "\n";
$cdata->replaceWith(...$emptyFragment->childNodes);
echo $dom->saveXML(), "\n";

$cdata = $dom->createCDATASection('foo');
$dom->appendChild($cdata);
$cdata->replaceWith(...$emptyFragment->childNodes);
echo $dom->saveXML(), "\n";
?>
--EXPECT--
--- DOMElement test ---
<?xml version="1.0"?>
<root><node/></root>
<?xml version="1.0"?>
<root/>
<?xml version="1.0"?>
--- DOMDocumentFragment test ---
<foo/>
--- DOMDocument test ---
<?xml version="1.0"?>

--- DOMCharacterData test ---
<?xml version="1.0"?>
<![CDATA[foo]]>

<?xml version="1.0"?>

<?xml version="1.0"?>