Commit graph

1734 commits

Author SHA1 Message Date
Niels Dossche
aecf2a6e62
Fix GH-18877: \Dom\HTMLDocument querySelectorAll selecting only the first when using ~ and :has
Backports lexbor/lexbor@971faf11a5

Closes GH-19180.
2025-08-10 13:07:13 +02:00
DanielEScherzer
1eadf553f1
Arginfo: avoid using temporary zvals for initializing attribute values (#19141)
Instead of
* adding a zval on the stack
* initializing it
* copying the value to the attribute

Just initialize the value directly in the zend_attribute_arg
2025-07-21 13:33:51 -07:00
Niels Dossche
03a9f03822
Migrate from xmlNewNode to xmlNewDocNode (#19182)
The former is discouraged [1].

[1] https://gnome.pages.gitlab.gnome.org/libxml2/html/tree_8h.html#aa39c05fb472571ed00e38c065e67d2ec
2025-07-19 23:29:04 +02:00
Daniel Scherzer
142e378618 Arginfo: add and use known strings for attribute values 2025-07-14 17:31:22 -07:00
Niels Dossche
9121b015c1
Implement GH-18550: Implement getElementsByClassName() (#19108)
Spec: https://dom.spec.whatwg.org/#ref-for-dom-element-getelementsbyclassname
2025-07-14 21:53:37 +02:00
Niels Dossche
f11ea2ae13 Refactor dom_html_collection_named_item()
This factors out the specific objmap handling to virtual functions.
This is the last step in preparation for GH-18550.
2025-07-11 12:29:29 +02:00
Niels Dossche
a2d65354a0 dom: Rename get_named_item -> get_ns_named_item, and has_named_item -> has_ns_named_item 2025-07-11 12:29:29 +02:00
Niels Dossche
4aa8c2fe5d
dom: Remove unnecessary objmap ptr null checks (#19092) 2025-07-11 10:35:14 +02:00
Niels Dossche
e013b4a91e
Make cloning DOM node lists, maps, and collections fail
This never worked and creates a broken object,
and on master can cause a crash with foreach.
It makes no sense to fix a behaviour that never worked, block it
instead.

Closes GH-19089.
2025-07-11 10:34:25 +02:00
DanielEScherzer
9225cb45ac
Make zend_register_*_constant() functions return pointers, use them (#19029)
Have each of the specialized methods for registering a constant return a
pointer to the registered constant the same way that the generic
`zend_register_constant()` function does, and use those in the generated
arginfo files to avoid needing to search for a constant that was just
registered in order to add attributes to it.
2025-07-07 12:23:52 -07:00
Niels Dossche
30662e4e2b
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18979: DOM\XMLDocument::createComment() triggers undefined behavior with null byte
2025-07-01 18:51:31 +02:00
Niels Dossche
1d5089e574
Fix GH-18979: DOM\XMLDocument::createComment() triggers undefined behavior with null byte
Closes GH-18983.
2025-07-01 18:51:21 +02:00
Niels Dossche
c7c6a79bd0
Add support for ParentNode::$children (#18908)
ParentNode::$children returns a HTMLCollection of all directly
descendant child elements of a container.

I had to move around some properties such that the ParentNode property
offsets are always at a fixed offset, to simplify the code.
This also adds the necessary code to deal with GC cycles in
HTMLCollections.
Furthermore, we also disable cloning a HTMLCollection as that never
worked and furthermore it also conflicts with the [[SameObject]] WebIDL
requirement of $children.
2025-06-27 09:03:50 +02:00
DanielEScherzer
171501b93f
Replace @deprecated with #[\Deprecated] for internal constants (#18780)
Only covers constants declared via stub files, others will be handled
separately in a later commit.

Does not include the intl extension, since that had some errors relating to the
cpp code; that extension will be updated separately.
2025-06-26 11:27:15 -07:00
Gina Peter Banyard
b068bef45d ext/dom: Remove bool type coercions in tests 2025-06-23 14:29:52 +02:00
Niels Dossche
9b6df109c7
Don't use the obj_map cache for attributes (#18895) 2025-06-22 12:31:06 +02:00
Niels Dossche
479e9be45d Store hash table entry directly in dom_nnodemap_object
Splits the purpose of the baseobj_zv: now no longer either is an array
or an object. Stores the hash table pointer directly, if used.
2025-06-22 12:30:50 +02:00
Niels Dossche
8736342782 Pack dom_nnodemap_object fields together with a union that can't be active at the same time 2025-06-22 12:30:50 +02:00
Niels Dossche
26aea0ed37 Tweak sizes of some dom_nnodemap_object fields
We don't have to pack the bools, and the cached index would better be a
zend_long so we don't get implicit narrowing.
2025-06-22 12:30:50 +02:00
Niels Dossche
8526de84a5 Move common obj_map API functions to obj_map.c 2025-06-22 12:30:50 +02:00
Niels Dossche
ff0a2cff05 Refactor implementation of DOM nodelists, named maps, and iterators
The code was really messy with lots of checks and inconsistencies.
This splits everything up into different functions and now everything is
relayed to a handler vtable.
2025-06-21 22:17:33 +02:00
Niels Dossche
4fadf647d2 Refactor dom_nnodemap_objects_new()
- Use ecalloc() to not miss initializing any field.
- Merge declarations and assignments.
2025-06-21 22:17:33 +02:00
Gina Peter Banyard
27e485d22e Merge branch 'PHP-8.4' 2025-06-20 19:09:02 +02:00
Gina Peter Banyard
940441106d ext/dom: Fix new MSVC compiler warning
Closes GH-18889
2025-06-20 19:08:33 +02:00
Niels Dossche
307ff3bdea
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18744: PHP 8.4 classList works not correctly if copy HTMLElement by clone keyword.
2025-06-04 18:59:21 +02:00
Niels Dossche
111072a9f0
Fix GH-18744: PHP 8.4 classList works not correctly if copy HTMLElement by clone keyword.
The $classList property is special in the sense that it's a cached
object instance per (HTML)Element instance. The reason for this design
is because it has the [[SameObject]] IDL attribute.
Cloning in PHP also clones the properties, so it also clones the cached
instance. To solve this, we undo this by resetting the backing storage.

Closes GH-18749.
2025-06-04 18:59:05 +02:00
Tim Düsterhus
4c5a6b0e8d
tree-wide: Remove stacktraces from tests testing throwing clones (#18748)
This is in preparation for the possible future transformation of `clone` into a
function call, but also meaningful on its own, since the purpose of the tests
is not to test the stack trace generation, but rather that an exception was
thrown. It also cleans up some unreachable code in the tests.
2025-06-03 20:08:47 +02:00
Niels Dossche
9e9db0b22f
Update Lexbor patches for non-string attribute
This should fix the final sub-issue of GH-17687.

Closes GH-18691.
2025-05-28 23:34:08 +02:00
Máté Kocsis
7f59fccd52
Create separate lexbor extension (#18538)
An always enabled lexbor extension is added, containing the lexbor library that was separated from ext/dom extension in preparation of https://wiki.php.net/rfc/url_parsing_api. While at it, the lexbor library is upgraded to 2.5.0.

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Gina Peter Banyard <girgias@php.net>
2025-05-25 14:12:44 +02:00
Niels Dossche
efaae93e48
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18597: Heap-buffer-overflow in zend_alloc.c when assigning string with UTF-8 bytes
2025-05-20 21:32:27 +02:00
Niels Dossche
40e667280b
Fix GH-18597: Heap-buffer-overflow in zend_alloc.c when assigning string with UTF-8 bytes
xmlSave() also can flush in some cases. When the encoding is not
available this can fail for short inputs, resulting in an empty string
which is interned but then wrongly tagged by RETURN_NEW_STR.
Fix this by checking the error condition and switching to RETURN_STR for
defense-in-depth.

This issue also exists on 8.3, but does not crash; however, due to the
different API usage internally I cannot easily fix it on 8.3. There it
gives a partial output.

Closes GH-18606.
2025-05-20 21:32:17 +02:00
Niels Dossche
a3fa5ae57b
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix deprecation warning for libxml SAX header (#18594)
2025-05-19 19:11:30 +02:00
Niels Dossche
9bf140afb4
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix deprecation warning for libxml SAX header (#18594)
2025-05-19 19:11:22 +02:00
Niels Dossche
92a0cc7d94
Fix deprecation warning for libxml SAX header (#18594)
This header is deprecated, but fortunately it isn't actually used.
2025-05-19 19:10:27 +02:00
Niels Dossche
05618e7e0b
Merge branch 'PHP-8.4'
* PHP-8.4:
  Backport lexbor/lexbor@814e0bce97 (#18574)
2025-05-16 20:28:16 +02:00
Niels Dossche
dbc7c5f34a
Backport lexbor/lexbor@814e0bce97 (#18574)
Co-authored-by: Alexander Borisov <lex.borisov@gmail.com>
2025-05-16 20:27:56 +02:00
Niels Dossche
b6667c471c
Merge branch 'PHP-8.4'
* PHP-8.4:
  Backport lexbor/lexbor#274
2025-05-04 12:58:07 +02:00
Niels Dossche
42ad1c64bf
Backport lexbor/lexbor#274
Co-authored-by: Alex Peattie <alexpeattie@gmail.com>

Closes GH-18490.
2025-05-04 12:57:54 +02:00
Niels Dossche
285c9f0dca
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix DOM tests for upcoming libxml2 serializer changes
2025-04-23 18:30:05 +02:00
Niels Dossche
94b58239e8
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix DOM tests for upcoming libxml2 serializer changes
2025-04-23 18:30:00 +02:00
Niels Dossche
d6e70e7053
Fix DOM tests for upcoming libxml2 serializer changes
DOM HTML serializer will be closer compliant to HTML5 in the next
libxml2 version, so the tests need to be adapted.
Ref: https://gitlab.gnome.org/GNOME/libxml2/-/merge_requests/309

Closes GH-18406.
2025-04-23 18:29:44 +02:00
Niels Dossche
f39c07a3bb DOM/XPath: Use RETURN_NEW_STR
These strings are newly allocated and can't be interned, so we can use
RETURN_NEW_STR.
2025-04-19 18:00:00 +02:00
Niels Dossche
35e96f621b DOM/XPath: Use ZSTR_LEN abstraction instead of direct member access 2025-04-19 18:00:00 +02:00
Niels Dossche
91a310e603
Get rid of separate DOM HashPosition member (#18354)
Besides the fact that this is only used for DOM_NODESET and thus makes
no sense of being on the iterator itself, it's also redundant now that
we have the index member.
2025-04-19 17:59:48 +02:00
Niels Dossche
3ba725a556
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:42 +02:00
Niels Dossche
a019fbd970
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18309: ipv6 filter integer overflow
  Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
2025-04-11 23:36:12 +02:00
Niels Dossche
ba0853888d
Fix GH-18304: Changing the properties of a DateInterval through dynamic properties triggers a SegFault
For dynamic fetches the cache_slot will be NULL, so we have to check for
that when resetting the cache. For zip and xmlreader this couldn't
easily be tested because of a lack of writable properties.

Closes GH-18307.
2025-04-11 23:33:58 +02:00
Niels Dossche
0733e453c7
Remove useless operations in namespace_compat (#18182)
We never use the return value, so we can avoid a double lookup and a
return.
2025-03-29 22:46:18 +01:00
Niels Dossche
b450a9c826
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix xinclude destruction of live attributes
2025-03-18 22:04:29 +01:00
Niels Dossche
2c45d67ad3
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix xinclude destruction of live attributes
2025-03-18 22:04:13 +01:00