Skip to content

Commit 14b6c98

Browse files
authored
[RFC] Add a way to opt-in ext/dom spec compliance (#13031)
RFC: https://wiki.php.net/rfc/opt_in_dom_spec_compliance
1 parent f438b3b commit 14b6c98

File tree

255 files changed

+14756
-2647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+14756
-2647
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ PHP NEWS
3636
. Handle OOM more consistently. (nielsdos)
3737
. Implemented "Improve callbacks in ext/dom and ext/xsl" RFC. (nielsdos)
3838
. Added DOMXPath::quote() static method. (divinity76)
39+
. Implemented opt-in ext/dom spec compliance RFC. (nielsdos)
3940

4041
- Fileinfo:
4142
. Update to libmagic 5.45. (nielsdos)

UPGRADING

+16-8
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,6 @@ PHP 8.4 UPGRADE NOTES
186186
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS.
187187
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY.
188188
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC.
189-
. Implemented DOM HTML5 parsing and serialization.
190-
RFC: https://wiki.php.net/rfc/domdocument_html5_parser.
191-
This RFC adds the new DOM namespace along with class and constant aliases.
192-
There are two new classes to handle HTML and XML documents:
193-
DOM\HTMLDocument and DOM\XMLDocument.
194-
These classes provide a cleaner API to handle HTML and XML documents.
195-
Furthermore, the DOM\HTMLDocument class implements spec-compliant HTML5
196-
parsing and serialization.
197189
. It is now possible to pass any callable to registerPhpFunctions().
198190
RFC: https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl
199191

@@ -453,6 +445,22 @@ PHP 8.4 UPGRADE NOTES
453445
7. New Classes and Interfaces
454446
========================================
455447

448+
- DOM:
449+
. Implemented DOM HTML5 parsing and serialization.
450+
RFC: https://wiki.php.net/rfc/domdocument_html5_parser.
451+
This RFC adds the new DOM namespace along with new classes and
452+
constant aliases.
453+
There are two new classes to handle HTML and XML documents:
454+
DOM\HTMLDocument and DOM\XMLDocument.
455+
These classes provide a cleaner API to handle HTML and XML documents.
456+
Furthermore, the DOM\HTMLDocument class implements spec-compliant HTML5
457+
parsing and serialization.
458+
. Implemented opt-in ext/dom spec compliance RFC.
459+
This adds new classes in the DOM namespace that correspond to modern
460+
equivalents to the old DOM classes in the global namespaces.
461+
The new classes follow the DOM living spec.
462+
RFC: https://wiki.php.net/rfc/opt_in_dom_spec_compliance
463+
456464
========================================
457465
8. Removed Extensions and SAPIs
458466
========================================

UPGRADING.INTERNALS

+3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ PHP 8.4 INTERNALS UPGRADE NOTES
143143
- The macros DOM_NO_ARGS() and DOM_NOT_IMPLEMENTED() have been removed.
144144
- New public APIs are available to handle callbacks from XPath, see
145145
xpath_callbacks.h.
146+
- Added public APIs to manipulate namespace data, see namespace_compat.h.
146147

147148
b. ext/random
148149
- The macro RAND_RANGE_BADSCALING() has been removed. The implementation
@@ -176,6 +177,8 @@ PHP 8.4 INTERNALS UPGRADE NOTES
176177
- Added php_libxml_pretend_ctx_error_ex() to emit errors as if they had come
177178
from libxml.
178179
- Removed the "properties" HashTable field from php_libxml_node_object.
180+
- Added a way to attached private data to a php_libxml_ref_obj.
181+
- Added a way to fix a class type onto php_libxml_ref_obj.
179182

180183
e. ext/date
181184
- Added the php_format_date_ex() API to format instances of php_date_obj.

ext/dom/attr.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,24 @@ PHP_METHOD(DOMAttr, __construct)
7272
/* {{{ name string
7373
readonly=yes
7474
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1112119403
75+
Modern spec URL: https://dom.spec.whatwg.org/#dom-attr-name
7576
Since:
7677
*/
7778
zend_result dom_attr_name_read(dom_object *obj, zval *retval)
7879
{
79-
xmlAttrPtr attrp;
80-
81-
attrp = (xmlAttrPtr) dom_object_get_node(obj);
80+
xmlAttrPtr attrp = (xmlAttrPtr) dom_object_get_node(obj);
8281

8382
if (attrp == NULL) {
8483
php_dom_throw_error(INVALID_STATE_ERR, 1);
8584
return FAILURE;
8685
}
8786

88-
ZVAL_STRING(retval, (char *) attrp->name);
87+
if (php_dom_follow_spec_intern(obj)) {
88+
zend_string *str = dom_node_get_node_name_attribute_or_element((xmlNodePtr) attrp, false);
89+
ZVAL_NEW_STR(retval, str);
90+
} else {
91+
ZVAL_STRING(retval, (char *) attrp->name);
92+
}
8993

9094
return SUCCESS;
9195
}
@@ -99,7 +103,7 @@ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-86
99103
*/
100104
zend_result dom_attr_specified_read(dom_object *obj, zval *retval)
101105
{
102-
/* TODO */
106+
/* From spec: "useless; always returns true" */
103107
ZVAL_TRUE(retval);
104108
return SUCCESS;
105109
}
@@ -147,7 +151,13 @@ zend_result dom_attr_value_write(dom_object *obj, zval *newval)
147151
zend_string *str = Z_STR_P(newval);
148152

149153
dom_remove_all_children((xmlNodePtr) attrp);
150-
xmlNodeSetContentLen((xmlNodePtr) attrp, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str));
154+
155+
if (php_dom_follow_spec_intern(obj)) {
156+
xmlNodePtr node = xmlNewDocTextLen(attrp->doc, BAD_CAST ZSTR_VAL(str), ZSTR_LEN(str));
157+
xmlAddChild((xmlNodePtr) attrp, node);
158+
} else {
159+
xmlNodeSetContentLen((xmlNodePtr) attrp, BAD_CAST ZSTR_VAL(str), ZSTR_LEN(str));
160+
}
151161

152162
return SUCCESS;
153163
}

0 commit comments

Comments
 (0)