Skip to content

Commit e76b62b

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix empty argument cases for DOMParentNode methods Fix DOMCharacterData::replaceWith() with itself Fix incorrect attribute existence check in DOMElement::setAttributeNodeNS() Fix DOMEntity field getter bugs
2 parents d6a795b + abb1d2e commit e76b62b

10 files changed

+281
-36
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ PHP NEWS
66
. Fixed bug GH-11716 (cli server crashes on SIGINT when compiled with
77
ZEND_RC_DEBUG=1). (nielsdos)
88

9+
- DOM:
10+
. Fix DOMEntity field getter bugs. (nielsdos)
11+
. Fix incorrect attribute existence check in DOMElement::setAttributeNodeNS.
12+
(nielsdos)
13+
. Fix DOMCharacterData::replaceWith() with itself. (nielsdos)
14+
. Fix empty argument cases for DOMParentNode methods. (nielsdos)
15+
916
- FFI:
1017
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)
1118

ext/dom/characterdata.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,12 @@ PHP_METHOD(DOMCharacterData, remove)
364364

365365
PHP_METHOD(DOMCharacterData, after)
366366
{
367-
int argc;
367+
int argc = 0;
368368
zval *args, *id;
369369
dom_object *intern;
370370
xmlNode *context;
371371

372-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
372+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
373373
RETURN_THROWS();
374374
}
375375

@@ -381,12 +381,12 @@ PHP_METHOD(DOMCharacterData, after)
381381

382382
PHP_METHOD(DOMCharacterData, before)
383383
{
384-
int argc;
384+
int argc = 0;
385385
zval *args, *id;
386386
dom_object *intern;
387387
xmlNode *context;
388388

389-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
389+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
390390
RETURN_THROWS();
391391
}
392392

@@ -398,20 +398,19 @@ PHP_METHOD(DOMCharacterData, before)
398398

399399
PHP_METHOD(DOMCharacterData, replaceWith)
400400
{
401-
int argc;
401+
int argc = 0;
402402
zval *args, *id;
403403
dom_object *intern;
404404
xmlNode *context;
405405

406-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
406+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
407407
RETURN_THROWS();
408408
}
409409

410410
id = ZEND_THIS;
411411
DOM_GET_OBJ(context, id, xmlNodePtr, intern);
412412

413-
dom_parent_node_after(intern, args, argc);
414-
dom_child_node_remove(intern);
413+
dom_child_replace_with(intern, args, argc);
415414
}
416415

417416
#endif

ext/dom/document.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,12 +2092,12 @@ Since: DOM Living Standard (DOM4)
20922092
*/
20932093
PHP_METHOD(DOMDocument, append)
20942094
{
2095-
int argc;
2095+
int argc = 0;
20962096
zval *args, *id;
20972097
dom_object *intern;
20982098
xmlNode *context;
20992099

2100-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
2100+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
21012101
RETURN_THROWS();
21022102
}
21032103

@@ -2113,12 +2113,12 @@ Since: DOM Living Standard (DOM4)
21132113
*/
21142114
PHP_METHOD(DOMDocument, prepend)
21152115
{
2116-
int argc;
2116+
int argc = 0;
21172117
zval *args, *id;
21182118
dom_object *intern;
21192119
xmlNode *context;
21202120

2121-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
2121+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
21222122
RETURN_THROWS();
21232123
}
21242124

ext/dom/documentfragment.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ Since: DOM Living Standard (DOM4)
135135
*/
136136
PHP_METHOD(DOMDocumentFragment, append)
137137
{
138-
int argc;
138+
int argc = 0;
139139
zval *args, *id;
140140
dom_object *intern;
141141
xmlNode *context;
142142

143-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
143+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
144144
RETURN_THROWS();
145145
}
146146

@@ -156,12 +156,12 @@ Since: DOM Living Standard (DOM4)
156156
*/
157157
PHP_METHOD(DOMDocumentFragment, prepend)
158158
{
159-
int argc;
159+
int argc = 0;
160160
zval *args, *id;
161161
dom_object *intern;
162162
xmlNode *context;
163163

164-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
164+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
165165
RETURN_THROWS();
166166
}
167167

ext/dom/element.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ PHP_METHOD(DOMElement, setAttributeNodeNS)
862862

863863
nsp = attrp->ns;
864864
if (nsp != NULL) {
865-
existattrp = xmlHasNsProp(nodep, nsp->href, attrp->name);
865+
existattrp = xmlHasNsProp(nodep, attrp->name, nsp->href);
866866
} else {
867867
existattrp = xmlHasProp(nodep, attrp->name);
868868
}
@@ -1137,12 +1137,12 @@ PHP_METHOD(DOMElement, remove)
11371137

11381138
PHP_METHOD(DOMElement, after)
11391139
{
1140-
int argc;
1140+
int argc = 0;
11411141
zval *args, *id;
11421142
dom_object *intern;
11431143
xmlNode *context;
11441144

1145-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
1145+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
11461146
RETURN_THROWS();
11471147
}
11481148

@@ -1154,12 +1154,12 @@ PHP_METHOD(DOMElement, after)
11541154

11551155
PHP_METHOD(DOMElement, before)
11561156
{
1157-
int argc;
1157+
int argc = 0;
11581158
zval *args, *id;
11591159
dom_object *intern;
11601160
xmlNode *context;
11611161

1162-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
1162+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
11631163
RETURN_THROWS();
11641164
}
11651165

@@ -1174,12 +1174,12 @@ Since: DOM Living Standard (DOM4)
11741174
*/
11751175
PHP_METHOD(DOMElement, append)
11761176
{
1177-
int argc;
1177+
int argc = 0;
11781178
zval *args, *id;
11791179
dom_object *intern;
11801180
xmlNode *context;
11811181

1182-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
1182+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
11831183
RETURN_THROWS();
11841184
}
11851185

@@ -1195,12 +1195,12 @@ Since: DOM Living Standard (DOM4)
11951195
*/
11961196
PHP_METHOD(DOMElement, prepend)
11971197
{
1198-
int argc;
1198+
int argc = 0;
11991199
zval *args, *id;
12001200
dom_object *intern;
12011201
xmlNode *context;
12021202

1203-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
1203+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
12041204
RETURN_THROWS();
12051205
}
12061206

@@ -1216,12 +1216,12 @@ Since: DOM Living Standard (DOM4)
12161216
*/
12171217
PHP_METHOD(DOMElement, replaceWith)
12181218
{
1219-
int argc;
1219+
int argc = 0;
12201220
zval *args, *id;
12211221
dom_object *intern;
12221222
xmlNode *context;
12231223

1224-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) {
1224+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "*", &args, &argc) == FAILURE) {
12251225
RETURN_THROWS();
12261226
}
12271227

ext/dom/entity.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
/*
2828
* class DOMEntity extends DOMNode
2929
*
30-
* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-527DCFF2
30+
* URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-527DCFF2
3131
* Since:
3232
*/
3333

3434
/* {{{ publicId string
3535
readonly=yes
36-
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-D7303025
36+
URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7303025
3737
Since:
3838
*/
3939
int dom_entity_public_id_read(dom_object *obj, zval *retval)
@@ -45,7 +45,7 @@ int dom_entity_public_id_read(dom_object *obj, zval *retval)
4545
return FAILURE;
4646
}
4747

48-
if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
48+
if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY || !nodep->ExternalID) {
4949
ZVAL_NULL(retval);
5050
} else {
5151
ZVAL_STRING(retval, (char *) (nodep->ExternalID));
@@ -58,7 +58,7 @@ int dom_entity_public_id_read(dom_object *obj, zval *retval)
5858

5959
/* {{{ systemId string
6060
readonly=yes
61-
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-D7C29F3E
61+
URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-D7C29F3E
6262
Since:
6363
*/
6464
int dom_entity_system_id_read(dom_object *obj, zval *retval)
@@ -83,13 +83,12 @@ int dom_entity_system_id_read(dom_object *obj, zval *retval)
8383

8484
/* {{{ notationName string
8585
readonly=yes
86-
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-6ABAEB38
86+
URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6ABAEB38
8787
Since:
8888
*/
8989
int dom_entity_notation_name_read(dom_object *obj, zval *retval)
9090
{
9191
xmlEntity *nodep = (xmlEntity *) dom_object_get_node(obj);
92-
char *content;
9392

9493
if (nodep == NULL) {
9594
php_dom_throw_error(INVALID_STATE_ERR, 1);
@@ -99,9 +98,12 @@ int dom_entity_notation_name_read(dom_object *obj, zval *retval)
9998
if (nodep->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) {
10099
ZVAL_NULL(retval);
101100
} else {
102-
content = (char *) xmlNodeGetContent((xmlNodePtr) nodep);
103-
ZVAL_STRING(retval, content);
104-
xmlFree(content);
101+
/* According to spec, NULL is only allowed for unparsed entities, if it's not set we should use the empty string. */
102+
if (!nodep->content) {
103+
ZVAL_EMPTY_STRING(retval);
104+
} else {
105+
ZVAL_STRING(retval, (const char *) nodep->content);
106+
}
105107
}
106108

107109
return SUCCESS;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
DOMCharacterData::replaceWith() with itself
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$dom = new DOMDocument;
8+
$dom->loadXML('<?xml version="1.0"?><container><![CDATA[Hello]]></container>');
9+
$cdata = $dom->documentElement->firstChild;
10+
$cdata->replaceWith($cdata);
11+
echo $dom->saveXML();
12+
?>
13+
--EXPECT--
14+
<?xml version="1.0"?>
15+
<container><![CDATA[Hello]]></container>

ext/dom/tests/DOMEntity_fields.phpt

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
--TEST--
2+
DOMEntity fields
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$xmlString = <<<XML
8+
<?xml version="1.0"?>
9+
<!DOCTYPE test [
10+
<!ENTITY sampleInternalEntity "This is a sample entity value.">
11+
<!ENTITY sampleExternalSystemWithNotationName SYSTEM "external.stuff" NDATA stuff>
12+
<!ENTITY sampleExternalSystemWithoutNotationName SYSTEM "external.stuff" NDATA >
13+
<!ENTITY sampleExternalPublicWithNotationName1 PUBLIC "public id" "external.stuff" NDATA stuff>
14+
<!ENTITY sampleExternalPublicWithNotationName2 PUBLIC "" "external.stuff" NDATA stuff>
15+
<!ENTITY sampleExternalPublicWithoutNotationName1 PUBLIC "public id" "external.stuff" NDATA >
16+
<!ENTITY sampleExternalPublicWithoutNotationName2 PUBLIC "" "external.stuff" NDATA >
17+
]>
18+
<root/>
19+
XML;
20+
21+
$dom = new DOMDocument();
22+
$dom->loadXML($xmlString);
23+
24+
// Sort them, the iteration order isn't defined
25+
$entities = iterator_to_array($dom->doctype->entities);
26+
ksort($entities);
27+
28+
foreach ($entities as $entity) {
29+
echo "Entity name: {$entity->nodeName}\n";
30+
echo "publicId: ";
31+
var_dump($entity->publicId);
32+
echo "systemId: ";
33+
var_dump($entity->systemId);
34+
echo "notationName: ";
35+
var_dump($entity->notationName);
36+
echo "actualEncoding: ";
37+
var_dump($entity->actualEncoding);
38+
echo "encoding: ";
39+
var_dump($entity->encoding);
40+
echo "version: ";
41+
var_dump($entity->version);
42+
echo "\n";
43+
}
44+
?>
45+
--EXPECT--
46+
Entity name: sampleExternalPublicWithNotationName1
47+
publicId: string(9) "public id"
48+
systemId: string(14) "external.stuff"
49+
notationName: string(5) "stuff"
50+
actualEncoding: NULL
51+
encoding: NULL
52+
version: NULL
53+
54+
Entity name: sampleExternalPublicWithNotationName2
55+
publicId: string(0) ""
56+
systemId: string(14) "external.stuff"
57+
notationName: string(5) "stuff"
58+
actualEncoding: NULL
59+
encoding: NULL
60+
version: NULL
61+
62+
Entity name: sampleExternalPublicWithoutNotationName1
63+
publicId: string(9) "public id"
64+
systemId: string(14) "external.stuff"
65+
notationName: string(0) ""
66+
actualEncoding: NULL
67+
encoding: NULL
68+
version: NULL
69+
70+
Entity name: sampleExternalPublicWithoutNotationName2
71+
publicId: string(0) ""
72+
systemId: string(14) "external.stuff"
73+
notationName: string(0) ""
74+
actualEncoding: NULL
75+
encoding: NULL
76+
version: NULL
77+
78+
Entity name: sampleExternalSystemWithNotationName
79+
publicId: NULL
80+
systemId: string(14) "external.stuff"
81+
notationName: string(5) "stuff"
82+
actualEncoding: NULL
83+
encoding: NULL
84+
version: NULL
85+
86+
Entity name: sampleExternalSystemWithoutNotationName
87+
publicId: NULL
88+
systemId: string(14) "external.stuff"
89+
notationName: string(0) ""
90+
actualEncoding: NULL
91+
encoding: NULL
92+
version: NULL
93+
94+
Entity name: sampleInternalEntity
95+
publicId: NULL
96+
systemId: NULL
97+
notationName: NULL
98+
actualEncoding: NULL
99+
encoding: NULL
100+
version: NULL

0 commit comments

Comments
 (0)