Skip to content

[RFC] Add a way to opt-in ext/dom spec compliance #13031

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

Merged
merged 218 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 207 commits
Commits
Show all changes
218 commits
Select commit Hold shift + click to select a range
df3e034
Add and adapt helper functions for checking spec compliant mode
nielsdos Dec 14, 2023
d5a65d3
Implement spec-compliant reconciliation
nielsdos Dec 14, 2023
a0dcae0
Add todo
nielsdos Dec 14, 2023
8ea661c
Fix attribute entity subsitution
nielsdos Dec 14, 2023
9c96791
Fix edge case of splitText() not throwing an exception
nielsdos Dec 14, 2023
c3afad0
Move to DOMDocument only
nielsdos Dec 14, 2023
370e18a
Implement spec checks for createCDATASection
nielsdos Dec 14, 2023
23c253c
Implement spec checks for createProcessingInstruction
nielsdos Dec 14, 2023
5b06d5b
Add additional import test
nielsdos Dec 14, 2023
abce5af
Use common API for creating a fully qualified name
nielsdos Dec 15, 2023
0b2213b
Implement spec-compliant behaviour for DOMElement::$tagName
nielsdos Dec 16, 2023
f834bc5
Start of new namespace compatibility implementation
nielsdos Dec 16, 2023
9fd9347
Use new common namespace API
nielsdos Dec 16, 2023
1cf3493
Make getAttributeNames() ignore internal namespace declarations in sp…
nielsdos Dec 16, 2023
57c7079
Use namespace concatenation helper
nielsdos Dec 16, 2023
6926035
Add todo
nielsdos Dec 16, 2023
db957ac
Implement spec-compliant behaviour for DOMNode::$nodeName
nielsdos Dec 16, 2023
1ed8159
Enable test that previously didn't work because of ext/dom spec bugs
nielsdos Dec 16, 2023
42d0c66
Make createAttributeNs spec compliant
nielsdos Dec 16, 2023
851ba8c
Fix spec-compliance of setAttributeNode(NS)
nielsdos Dec 16, 2023
a37c5f2
Remove unused code
nielsdos Dec 16, 2023
5f5b5e6
Make isEqualNode spec compliant after attribute handling change
nielsdos Dec 16, 2023
cb46b54
Fix serialization bug
nielsdos Dec 16, 2023
bbd013b
Add test for legacy entity expansion behaviour
nielsdos Dec 16, 2023
ac9461d
Make createElement spec compliant
nielsdos Dec 16, 2023
e9dddf1
Generalise fast namespace checking
nielsdos Dec 16, 2023
719dc2f
Make createAttribute() spec compliant
nielsdos Dec 16, 2023
ddab138
Make createElementNS spec compliant
nielsdos Dec 16, 2023
07fd6c1
Fix crashes
nielsdos Dec 16, 2023
8f7f0df
Fix another crash
nielsdos Dec 16, 2023
d212cec
Remove obsolete todo
nielsdos Dec 16, 2023
4e2a3b9
Namespace fixes
nielsdos Dec 16, 2023
a7af06a
Make getElementsByTagName spec compliant
nielsdos Dec 16, 2023
76c9777
Mark date in comment
nielsdos Dec 16, 2023
1b5c5e0
Make Document::$documentURI spec compliant
nielsdos Dec 16, 2023
0ac12c9
Define namespaces as close to the element as possible
nielsdos Dec 17, 2023
6254d73
Make prefix unmodifiable
nielsdos Dec 17, 2023
89f6e43
Fix test case output
nielsdos Dec 17, 2023
7af8075
Move tests
nielsdos Dec 17, 2023
f83376d
Fix spec compliance of pre-insertion validation
nielsdos Dec 17, 2023
aa6fee5
Remove TODO
nielsdos Dec 17, 2023
8e7978d
Fix adjacent text merging bug
nielsdos Dec 17, 2023
ac21691
Add test for getElementsByTagNameNS
nielsdos Dec 17, 2023
22edb0f
Tests for isEqualNode
nielsdos Dec 17, 2023
956de2c
Fix new issues
nielsdos Dec 17, 2023
f9016e0
Spec compliance part 2 for setAttributeNode
nielsdos Dec 17, 2023
2e99976
Make importNode throw when needed
nielsdos Dec 17, 2023
b3fde71
Make dtd importable and cloneable
nielsdos Dec 17, 2023
6250966
Make appendChild work with dtd
nielsdos Dec 17, 2023
e656a97
Fix attaching of attributes
nielsdos Dec 17, 2023
d660ed6
Correct condition
nielsdos Dec 17, 2023
dfc05d2
Lots of attribute handling fixes
nielsdos Dec 17, 2023
77521b8
Make getAttributeNodeNS() spec compliant
nielsdos Dec 17, 2023
904c4a5
Add test for getAttribute()
nielsdos Dec 17, 2023
852ee45
Make getAttributeNS() spec compliant
nielsdos Dec 17, 2023
f06c0e1
Avoid copying
nielsdos Dec 17, 2023
1bcbdcd
Fix stream path detection
nielsdos Dec 17, 2023
9bf0349
[ci skip] Add comment
nielsdos Dec 17, 2023
4a2df19
Avoid allocations
nielsdos Dec 17, 2023
074a1aa
Use request allocator if possible
nielsdos Dec 17, 2023
9254944
Test hasAttribute
nielsdos Dec 17, 2023
af194b3
Make hasAttributeNS spec compliant
nielsdos Dec 17, 2023
2d80cf0
Make removeAttribute() spec compliant
nielsdos Dec 17, 2023
fd59178
Cleanup
nielsdos Dec 17, 2023
2acaa10
Make removeAttributeNS() spec compliant
nielsdos Dec 17, 2023
64d2a39
Make setAttribute() spec compliant
nielsdos Dec 17, 2023
b31cfb4
Move setAttributeNS legacy implementation
nielsdos Dec 17, 2023
ff16b16
Make setAttributeNS() spec compliant
nielsdos Dec 17, 2023
e7dac91
Fixup testcase
nielsdos Dec 17, 2023
e42e2be
Specified is always true in modern-day dom
nielsdos Dec 17, 2023
c7bbcd5
Remove TODO, this is unfixable
nielsdos Dec 17, 2023
8cccffe
Not anymore
nielsdos Dec 17, 2023
5ca64e7
Cleanup
nielsdos Dec 18, 2023
449ce4a
Fix spec compliance of isDefaultNamespace
nielsdos Dec 18, 2023
628d0df
Faster textContent write
nielsdos Dec 18, 2023
a2392b6
Fix mistake in setAttributeNS
nielsdos Dec 18, 2023
3240bbd
Make lookupNamespaceURI() spec compliant
nielsdos Dec 18, 2023
0fc0519
Make lookupPrefix() spec compliant
nielsdos Dec 18, 2023
9c1181d
Fix name matching of getElementsByTagNameNS
nielsdos Dec 18, 2023
fa69cf1
Cleanup
nielsdos Dec 18, 2023
6015440
Fix setAttribute qualified name matching
nielsdos Dec 18, 2023
0261e8e
Demote DOMNameSpaceNode
nielsdos Dec 18, 2023
96b9da2
More namespace tests
nielsdos Dec 18, 2023
0f2f355
Make replaceChild() spec compliant
nielsdos Dec 18, 2023
c2bb363
Fix crash
nielsdos Dec 18, 2023
5b83301
Make toggleAttribute spec compliant
nielsdos Dec 18, 2023
d354127
Optimize oldNS use
nielsdos Dec 18, 2023
a8f5aae
Remove useless NULL check
nielsdos Dec 18, 2023
459e39f
Remove now-incorrect comment
nielsdos Dec 19, 2023
5c7e706
Split out pre-insertion validity check into separate method
nielsdos Dec 19, 2023
5670a22
Refactor parentnode.c and bring it closer to spec
nielsdos Dec 19, 2023
5845c79
Move function
nielsdos Dec 19, 2023
f3bc819
Rewrite large parts of parentnode.c to comply with spec
nielsdos Dec 19, 2023
93aad39
Fix static analysis complaints
nielsdos Dec 19, 2023
bcd7107
Make appendChild() spec compliant
nielsdos Dec 19, 2023
6acafc3
Fix spec compliance of insertAdjacent methods
nielsdos Dec 19, 2023
6cb15af
Make nodeValue null for elements
nielsdos Dec 19, 2023
42bd557
Fix issue with document properties and cloneNode
nielsdos Dec 20, 2023
0900497
Make DOMAttr::$name spec compliant
nielsdos Dec 20, 2023
499e006
Fixup attribute tests
nielsdos Dec 20, 2023
b314b95
Split off insertBefore
nielsdos Dec 20, 2023
8fa009f
Split off check
nielsdos Dec 20, 2023
2778697
Add missing invalidation
nielsdos Dec 20, 2023
35fbc4d
Do step 3 of pre-insert validity anyway for simplicity sake
nielsdos Dec 20, 2023
0f7aab9
Smarter freeing strategy
nielsdos Dec 20, 2023
47ed99a
Implement insertBefore according to spec
nielsdos Dec 20, 2023
12e47fc
Fixes to hierarchy checks
nielsdos Dec 20, 2023
4480793
Avoid memory allocation
nielsdos Dec 20, 2023
0dd7c26
Fix nodes becoming inaccessible after normalizing
nielsdos Dec 20, 2023
a449bc7
Avoid allocation
nielsdos Dec 20, 2023
15ee3e7
Make normalize spec compliant
nielsdos Dec 20, 2023
5de39f1
Fix prefix of xmlns after parsing
nielsdos Dec 20, 2023
ae977b7
Fix xlink attribute namespace
nielsdos Dec 20, 2023
6dffddf
Add test for namespaced attributes
nielsdos Dec 20, 2023
5b0c7ff
Normalization tests update
nielsdos Dec 20, 2023
f3d83c9
Make textContent spec compliant
nielsdos Dec 20, 2023
d359f07
Fix negative bounds in insertData
nielsdos Dec 20, 2023
c901097
Negative length in insertData
nielsdos Dec 20, 2023
1d3afce
Fix replaceData negative count
nielsdos Dec 20, 2023
6236996
substringData negative arguments
nielsdos Dec 20, 2023
1894f69
Fix reconciliation of attributes
nielsdos Dec 21, 2023
6c46137
Fix indent
nielsdos Dec 21, 2023
7501361
Move common tree walk code into php_dom_next_in_tree_order()
nielsdos Dec 21, 2023
1d28b16
Namespace reconciliation logic for elements
nielsdos Dec 21, 2023
bcbc4bf
Fix cloning a dtd node
nielsdos Dec 21, 2023
72edcf0
More testing
nielsdos Dec 21, 2023
5d47aba
Avoid duplicate work
nielsdos Dec 21, 2023
2073dd3
Split off function
nielsdos Dec 21, 2023
bb45275
Remove type check for now-unused libxml type
nielsdos Dec 21, 2023
6eb1895
Make DOMNamedNodeMap spec compliant
nielsdos Dec 21, 2023
e1df8dd
Directly call the right function instead of through the helper
nielsdos Dec 22, 2023
585d034
Smarter mangling
nielsdos Dec 22, 2023
f7b5c9f
Don't add too many UNEXPECTEDs to avoid moving too much code to cold …
nielsdos Dec 22, 2023
6093fa2
Make traversal method always inlined
nielsdos Dec 22, 2023
5b9beda
Improve performance of reconciliation
nielsdos Dec 22, 2023
45b72c2
More test coverage for normalization
nielsdos Dec 22, 2023
224bd78
Remove dead code
nielsdos Dec 22, 2023
f8480a5
More testing and get rid of special case
nielsdos Dec 22, 2023
c55c04c
More test coverage
nielsdos Dec 22, 2023
ecd9871
More tests for isDefaultNamespace
nielsdos Dec 22, 2023
c160db1
Better testing of setAttributeNode
nielsdos Dec 22, 2023
3a7427b
Comment with more explanation
nielsdos Dec 22, 2023
1faf7fd
Minor performance improvements
nielsdos Dec 23, 2023
b71e320
Import and clone spec compliance fixes
nielsdos Dec 23, 2023
c3ed9f7
Comments
nielsdos Dec 23, 2023
c19a95d
Mark namespace attributes at the front of the attribute list
nielsdos Dec 24, 2023
d70a990
Implement XML serialization
nielsdos Dec 25, 2023
f408c74
Propagate save error
nielsdos Dec 25, 2023
b837d73
Handle errors and encoding
nielsdos Dec 25, 2023
f27f8d2
Fixes
nielsdos Dec 25, 2023
5c21dee
Create namespace of attribtue as close to attribute's element as poss…
nielsdos Dec 26, 2023
61e0513
Add todo
nielsdos Dec 26, 2023
9dd7bdf
Remove redundant include
nielsdos Jan 10, 2024
3589f27
Improve dom_ns_fast_get_html_ns() logic
nielsdos Jan 10, 2024
9c34092
Test case where the XML is already formatted
nielsdos Jan 10, 2024
b138ffd
Test additional namespace bugs
nielsdos Jan 17, 2024
4d87be2
Fix closing the encoding handler
nielsdos Jan 24, 2024
c61cae7
New namespace compatibility implementation
nielsdos Jan 24, 2024
3fca2c8
Initial pass at splitting classes
nielsdos Feb 7, 2024
8da79f9
More test coverage for new types
nielsdos Feb 8, 2024
f6a0863
Don't declare the soon-to-be-deprecated namespace variant of PHP_ERR
nielsdos Feb 9, 2024
932b83c
Fix import implementation class type check, and test
nielsdos Feb 10, 2024
d43a491
Version is not nullable
nielsdos Feb 10, 2024
927f75a
Refactor dom_node_children_valid because it's usage is confusing
nielsdos Feb 10, 2024
acbae0a
Already did this
nielsdos Feb 10, 2024
fd9535e
Implement importLegacyNode
nielsdos Feb 10, 2024
3c927cb
Fix inconsistent handling of ns_mapper vs spec-compliance in cloning
nielsdos Feb 10, 2024
f78b2d7
xmlEncoding is not nullable
nielsdos Feb 10, 2024
3b8133e
Implement DTDNamedNodeMap
nielsdos Feb 10, 2024
5d55d84
Initial fixes for XPath
nielsdos Feb 10, 2024
6ef7fc6
Fix namespace node problem
nielsdos Feb 10, 2024
c1f5429
Split off namespace allocation code
nielsdos Feb 11, 2024
99a3cbb
Cleanup
nielsdos Feb 11, 2024
1ee0ef2
Print out namespace in noscript test
nielsdos Feb 11, 2024
da4623d
Update exception message
nielsdos Feb 11, 2024
36f95d9
Use fast ns checker more where possible
nielsdos Feb 14, 2024
9a04e79
Fix XPath and context node namespace registration
nielsdos Feb 14, 2024
4e55897
Fix type of baseURI
nielsdos Feb 16, 2024
db8d587
Corrections
nielsdos Feb 16, 2024
97edc64
Improve coverage of code using string macros
nielsdos Feb 17, 2024
9d87131
More test coverage for CharacterData edge cases
nielsdos Feb 17, 2024
b54ce01
Test createElement edge cases
nielsdos Feb 17, 2024
bf96916
Remove deprecated error type
nielsdos Feb 17, 2024
5f4ca9c
Test edge case of removeAttribute
nielsdos Feb 17, 2024
303ca80
Fix indent
nielsdos Feb 17, 2024
2758dc4
Remove dead code
nielsdos Feb 17, 2024
be07c52
Remove always-true check
nielsdos Feb 17, 2024
216a9fc
Test more edge cases for insertData
nielsdos Feb 17, 2024
4fd601b
Use class name from ce
nielsdos Feb 19, 2024
5566780
Serialize entity references too for compatibility
nielsdos Feb 19, 2024
19c913c
Make quote method available on new XPath class too
nielsdos Feb 23, 2024
7c22119
Make error message more accurate for old DOM
nielsdos Feb 23, 2024
81986a3
Rename tests for consistency
nielsdos Feb 23, 2024
90ff928
Fix unused variable warnings
nielsdos Feb 23, 2024
e4aebfb
Fix ext/xsl interaction with new DOM
nielsdos Feb 24, 2024
577169b
Make namespace APIs public
nielsdos Feb 24, 2024
f5a5ddc
Fix XSLTProcessor lifetime issue wrt namespaces
nielsdos Feb 24, 2024
2df9e30
Make dimension handlers in new DOM more strict
nielsdos Feb 24, 2024
725db63
Mark other object handlers static as well
nielsdos Feb 24, 2024
87bbca6
Remove useless free call
nielsdos Feb 29, 2024
436dd58
Cleanup
nielsdos Feb 29, 2024
1f245c7
Port over DOMImplementation
nielsdos Feb 29, 2024
a069341
Fix prefix of DOM\Attr
nielsdos Mar 3, 2024
3d62a3a
Fix unlikely memleak
nielsdos Mar 3, 2024
f0af56f
TEMPORARILY collapse test files so that GH UI doesn't break
nielsdos Mar 7, 2024
b2a7b78
Review comments part 1
nielsdos Mar 7, 2024
27efef4
Review fixes
nielsdos Mar 8, 2024
422595c
Initialize should_free_result to false instead everywhere
nielsdos Mar 8, 2024
42168a2
Implement numeric string handling for new DOM named dimension
nielsdos Mar 8, 2024
4afad64
Also numeric string handling for NodeList
nielsdos Mar 8, 2024
da46be3
Get rid of tentative returns
nielsdos Mar 9, 2024
934f797
Revert "TEMPORARILY collapse test files so that GH UI doesn't break"
nielsdos Mar 9, 2024
d5e6934
Extend test for bug47847
nielsdos Mar 9, 2024
7956d50
NEWS UPGRADING etc
nielsdos Mar 9, 2024
e0b520e
Fix test formatting
nielsdos Mar 9, 2024
922a7d8
Test extension
nielsdos Mar 9, 2024
7a847b1
Test improvements
nielsdos Mar 9, 2024
3812d1b
Cleanup test
nielsdos Mar 9, 2024
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@

# Vendored libraries
/ext/dom/lexbor/lexbor linguist-vendored

*.phpt linguist-generated
22 changes: 16 additions & 6 deletions ext/dom/attr.c
Original file line number Diff line number Diff line change
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
164 changes: 134 additions & 30 deletions ext/dom/characterdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
* Since:
*/

/* For some peculiar reason, many of these methods operate on unsigned numbers.
* Unfortunately, "old DOM" doesn't, so we have to conditionally convert...
* And the reason we're using "unsigned int" instead of "unsigned zend_long" is because libxml2 internally works with ints. */
static bool dom_convert_number_unsigned(dom_object *intern, zend_long input, unsigned int *output)
{
if (input < 0) {
if (php_dom_follow_spec_intern(intern)) {
*output = (unsigned int) input;
} else {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
return false;
}
} else {
*output = input;
}
return true;
}

/* {{{ data string
readonly=no
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-72AB8359
Expand Down Expand Up @@ -96,33 +114,44 @@ zend_result dom_characterdata_length_read(dom_object *obj, zval *retval)
/* }}} */

/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-6531BCCF
Modern spec URL: https://dom.spec.whatwg.org/#dom-characterdata-substringdata
Since:
*/
PHP_METHOD(DOMCharacterData, substringData)
{
zval *id;
xmlChar *cur;
xmlChar *substring;
xmlNodePtr node;
zend_long offset, count;
int length;
dom_object *intern;
zval *id;
xmlChar *cur;
xmlChar *substring;
xmlNodePtr node;
zend_long offset_input, count_input;
unsigned int count, offset;
int length;
dom_object *intern;

id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &offset, &count) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &offset_input, &count_input) == FAILURE) {
RETURN_THROWS();
}

DOM_GET_OBJ(node, id, xmlNodePtr, intern);

cur = node->content;
if (cur == NULL) {
RETURN_FALSE;
/* TODO: is this even possible? */
cur = BAD_CAST "";
}

length = xmlUTF8Strlen(cur);
if (ZEND_LONG_INT_OVFL(offset_input) || ZEND_LONG_INT_OVFL(count_input)) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}

if (offset < 0 || count < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count) || offset > length) {
if (!dom_convert_number_unsigned(intern, offset_input, &offset) || !dom_convert_number_unsigned(intern, count_input, &count)) {
RETURN_FALSE;
}

if (offset > length) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}
Expand All @@ -143,9 +172,10 @@ PHP_METHOD(DOMCharacterData, substringData)
/* }}} end dom_characterdata_substring_data */

/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-32791A2F
Modern spec URL: https://dom.spec.whatwg.org/#dom-characterdata-appenddata
Since:
*/
PHP_METHOD(DOMCharacterData, appendData)
static void dom_character_data_append_data(INTERNAL_FUNCTION_PARAMETERS, bool return_true)
{
zval *id;
xmlNode *nodep;
Expand All @@ -160,39 +190,63 @@ PHP_METHOD(DOMCharacterData, appendData)

DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
xmlTextConcat(nodep, (xmlChar *) arg, arg_len);
RETURN_TRUE;
if (return_true) {
RETURN_TRUE;
}
}

PHP_METHOD(DOMCharacterData, appendData)
{
dom_character_data_append_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}

PHP_METHOD(DOM_CharacterData, appendData)
{
dom_character_data_append_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}
/* }}} end dom_characterdata_append_data */

/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-3EDB695F
Modern spec URL: https://dom.spec.whatwg.org/#dom-characterdata-insertdata
Since:
*/
PHP_METHOD(DOMCharacterData, insertData)
static void dom_character_data_insert_data(INTERNAL_FUNCTION_PARAMETERS, bool return_true)
{
zval *id;
xmlChar *cur, *first, *second;
xmlNodePtr node;
char *arg;
zend_long offset;
zend_long offset_input;
unsigned int offset;
int length;
size_t arg_len;
dom_object *intern;

id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &offset, &arg, &arg_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &offset_input, &arg, &arg_len) == FAILURE) {
RETURN_THROWS();
}

DOM_GET_OBJ(node, id, xmlNodePtr, intern);

cur = node->content;
if (cur == NULL) {
RETURN_FALSE;
/* TODO: is this even possible? */
cur = BAD_CAST "";
}

length = xmlUTF8Strlen(cur);

if (offset < 0 || ZEND_LONG_INT_OVFL(offset) || offset > length) {
if (ZEND_LONG_INT_OVFL(offset_input)) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}

if (!dom_convert_number_unsigned(intern, offset_input, &offset)) {
RETURN_FALSE;
}

if (offset > length) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}
Expand All @@ -207,41 +261,60 @@ PHP_METHOD(DOMCharacterData, insertData)
xmlFree(first);
xmlFree(second);

RETURN_TRUE;
if (return_true) {
RETURN_TRUE;
}
}

PHP_METHOD(DOMCharacterData, insertData)
{
dom_character_data_insert_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}

PHP_METHOD(DOM_CharacterData, insertData)
{
dom_character_data_insert_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}
/* }}} end dom_characterdata_insert_data */

/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-7C603781
Modern spec URL: https://dom.spec.whatwg.org/#dom-characterdata-deletedata
Since:
*/
PHP_METHOD(DOMCharacterData, deleteData)
static void dom_character_data_delete_data(INTERNAL_FUNCTION_PARAMETERS, bool return_true)
{
zval *id;
xmlChar *cur, *substring, *second;
xmlNodePtr node;
zend_long offset, count;
zend_long offset, count_input;
unsigned int count;
int length;
dom_object *intern;

id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &offset, &count) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &offset, &count_input) == FAILURE) {
RETURN_THROWS();
}

DOM_GET_OBJ(node, id, xmlNodePtr, intern);

cur = node->content;
if (cur == NULL) {
RETURN_FALSE;
/* TODO: is this even possible? */
cur = BAD_CAST "";
}

length = xmlUTF8Strlen(cur);

if (offset < 0 || count < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count) || offset > length) {
if (offset < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count_input) || offset > length) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}

if (!dom_convert_number_unsigned(intern, count_input, &count)) {
RETURN_FALSE;
}

if (offset > 0) {
substring = xmlUTF8Strsub(cur, 0, (int)offset);
} else {
Expand All @@ -260,43 +333,62 @@ PHP_METHOD(DOMCharacterData, deleteData)
xmlFree(second);
xmlFree(substring);

RETURN_TRUE;
if (return_true) {
RETURN_TRUE;
}
}

PHP_METHOD(DOMCharacterData, deleteData)
{
dom_character_data_delete_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}

PHP_METHOD(DOM_CharacterData, deleteData)
{
dom_character_data_delete_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}
/* }}} end dom_characterdata_delete_data */

/* {{{ URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-E5CBA7FB
Modern spec URL: https://dom.spec.whatwg.org/#dom-characterdata-replacedata
Since:
*/
PHP_METHOD(DOMCharacterData, replaceData)
static void dom_character_data_replace_data(INTERNAL_FUNCTION_PARAMETERS, bool return_true)
{
zval *id;
xmlChar *cur, *substring, *second = NULL;
xmlNodePtr node;
char *arg;
zend_long offset, count;
zend_long offset, count_input;
unsigned int count;
int length;
size_t arg_len;
dom_object *intern;

id = ZEND_THIS;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lls", &offset, &count, &arg, &arg_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lls", &offset, &count_input, &arg, &arg_len) == FAILURE) {
RETURN_THROWS();
}

DOM_GET_OBJ(node, id, xmlNodePtr, intern);

cur = node->content;
if (cur == NULL) {
RETURN_FALSE;
/* TODO: is this even possible? */
cur = BAD_CAST "";
}

length = xmlUTF8Strlen(cur);

if (offset < 0 || count < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count) || offset > length) {
if (offset < 0 || ZEND_LONG_INT_OVFL(offset) || ZEND_LONG_INT_OVFL(count_input) || offset > length) {
php_dom_throw_error(INDEX_SIZE_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}

if (!dom_convert_number_unsigned(intern, count_input, &count)) {
RETURN_FALSE;
}

if (offset > 0) {
substring = xmlUTF8Strsub(cur, 0, (int)offset);
} else {
Expand All @@ -321,7 +413,19 @@ PHP_METHOD(DOMCharacterData, replaceData)
}
xmlFree(substring);

RETURN_TRUE;
if (return_true) {
RETURN_TRUE;
}
}

PHP_METHOD(DOMCharacterData, replaceData)
{
dom_character_data_replace_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, true);
}

PHP_METHOD(DOM_CharacterData, replaceData)
{
dom_character_data_replace_data(INTERNAL_FUNCTION_PARAM_PASSTHRU, false);
}
/* }}} end dom_characterdata_replace_data */

Expand Down
4 changes: 2 additions & 2 deletions ext/dom/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if test "$PHP_DOM" != "no"; then
$LEXBOR_DIR/ns/ns.c \
$LEXBOR_DIR/tag/tag.c"
PHP_NEW_EXTENSION(dom, [php_dom.c attr.c document.c \
xml_document.c html_document.c html5_serializer.c html5_parser.c namespace_compat.c \
xml_document.c html_document.c xml_serializer.c html5_serializer.c html5_parser.c namespace_compat.c \
domexception.c parentnode.c \
processinginstruction.c cdatasection.c \
documentfragment.c domimplementation.c \
Expand All @@ -49,7 +49,7 @@ if test "$PHP_DOM" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/$LEXBOR_DIR/ns)
PHP_ADD_BUILD_DIR($ext_builddir/$LEXBOR_DIR/tag)
PHP_SUBST(DOM_SHARED_LIBADD)
PHP_INSTALL_HEADERS([ext/dom], [xml_common.h xpath_callbacks.h])
PHP_INSTALL_HEADERS([ext/dom], [xml_common.h xpath_callbacks.h namespace_compat.h])
PHP_ADD_EXTENSION_DEP(dom, libxml)
])
fi
Loading