Skip to content

Commit

Permalink
[RFC] Add a way to opt-in ext/dom spec compliance (#13031)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos committed Mar 9, 2024
1 parent f438b3b commit 14b6c98
Show file tree
Hide file tree
Showing 255 changed files with 14,756 additions and 2,647 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -36,6 +36,7 @@ PHP NEWS
. Handle OOM more consistently. (nielsdos)
. Implemented "Improve callbacks in ext/dom and ext/xsl" RFC. (nielsdos)
. Added DOMXPath::quote() static method. (divinity76)
. Implemented opt-in ext/dom spec compliance RFC. (nielsdos)

- Fileinfo:
. Update to libmagic 5.45. (nielsdos)
Expand Down
24 changes: 16 additions & 8 deletions UPGRADING
Expand Up @@ -186,14 +186,6 @@ PHP 8.4 UPGRADE NOTES
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINS.
. Added constant DOMNode::DOCUMENT_POSITION_CONTAINED_BY.
. Added constant DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC.
. Implemented DOM HTML5 parsing and serialization.
RFC: https://wiki.php.net/rfc/domdocument_html5_parser.
This RFC adds the new DOM namespace along with class and constant aliases.
There are two new classes to handle HTML and XML documents:
DOM\HTMLDocument and DOM\XMLDocument.
These classes provide a cleaner API to handle HTML and XML documents.
Furthermore, the DOM\HTMLDocument class implements spec-compliant HTML5
parsing and serialization.
. It is now possible to pass any callable to registerPhpFunctions().
RFC: https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl

Expand Down Expand Up @@ -453,6 +445,22 @@ PHP 8.4 UPGRADE NOTES
7. New Classes and Interfaces
========================================

- DOM:
. Implemented DOM HTML5 parsing and serialization.
RFC: https://wiki.php.net/rfc/domdocument_html5_parser.
This RFC adds the new DOM namespace along with new classes and
constant aliases.
There are two new classes to handle HTML and XML documents:
DOM\HTMLDocument and DOM\XMLDocument.
These classes provide a cleaner API to handle HTML and XML documents.
Furthermore, the DOM\HTMLDocument class implements spec-compliant HTML5
parsing and serialization.
. Implemented opt-in ext/dom spec compliance RFC.
This adds new classes in the DOM namespace that correspond to modern
equivalents to the old DOM classes in the global namespaces.
The new classes follow the DOM living spec.
RFC: https://wiki.php.net/rfc/opt_in_dom_spec_compliance

========================================
8. Removed Extensions and SAPIs
========================================
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING.INTERNALS
Expand Up @@ -143,6 +143,7 @@ PHP 8.4 INTERNALS UPGRADE NOTES
- The macros DOM_NO_ARGS() and DOM_NOT_IMPLEMENTED() have been removed.
- New public APIs are available to handle callbacks from XPath, see
xpath_callbacks.h.
- Added public APIs to manipulate namespace data, see namespace_compat.h.

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

e. ext/date
- Added the php_format_date_ex() API to format instances of php_date_obj.
Expand Down
22 changes: 16 additions & 6 deletions ext/dom/attr.c
Expand Up @@ -72,20 +72,24 @@ PHP_METHOD(DOMAttr, __construct)
/* {{{ name string
readonly=yes
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-1112119403
Modern spec URL: https://dom.spec.whatwg.org/#dom-attr-name
Since:
*/
zend_result dom_attr_name_read(dom_object *obj, zval *retval)
{
xmlAttrPtr attrp;

attrp = (xmlAttrPtr) dom_object_get_node(obj);
xmlAttrPtr attrp = (xmlAttrPtr) dom_object_get_node(obj);

if (attrp == NULL) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
return FAILURE;
}

ZVAL_STRING(retval, (char *) attrp->name);
if (php_dom_follow_spec_intern(obj)) {
zend_string *str = dom_node_get_node_name_attribute_or_element((xmlNodePtr) attrp, false);
ZVAL_NEW_STR(retval, str);
} else {
ZVAL_STRING(retval, (char *) attrp->name);
}

return SUCCESS;
}
Expand All @@ -99,7 +103,7 @@ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-86
*/
zend_result dom_attr_specified_read(dom_object *obj, zval *retval)
{
/* TODO */
/* From spec: "useless; always returns true" */
ZVAL_TRUE(retval);
return SUCCESS;
}
Expand Down Expand Up @@ -147,7 +151,13 @@ zend_result dom_attr_value_write(dom_object *obj, zval *newval)
zend_string *str = Z_STR_P(newval);

dom_remove_all_children((xmlNodePtr) attrp);
xmlNodeSetContentLen((xmlNodePtr) attrp, (xmlChar *) ZSTR_VAL(str), ZSTR_LEN(str));

if (php_dom_follow_spec_intern(obj)) {
xmlNodePtr node = xmlNewDocTextLen(attrp->doc, BAD_CAST ZSTR_VAL(str), ZSTR_LEN(str));
xmlAddChild((xmlNodePtr) attrp, node);
} else {
xmlNodeSetContentLen((xmlNodePtr) attrp, BAD_CAST ZSTR_VAL(str), ZSTR_LEN(str));
}

return SUCCESS;
}
Expand Down

0 comments on commit 14b6c98

Please sign in to comment.