Commit graph

359 commits

Author SHA1 Message Date
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
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
Niels Dossche
d9329b1522
Fix xinclude destruction of live attributes
Follow-up for GH-17847 but now for attributes.

Closes GH-18100.
2025-03-18 22:01:56 +01:00
Niels Dossche
be3d128632
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17847: xinclude destroys live node
2025-02-21 22:27:53 +01:00
Niels Dossche
9becccef17
Fix GH-17847: xinclude destroys live node
dom_xinclude_strip_fallback_references() now also takes into account
xi:include nodes children. This now subsumes all work done normally by
the old start/end node removal, so we can remove that code and start
using XML_PARSE_NOXINCNODE.

Closes GH-17878.
2025-02-21 22:24:44 +01:00
Niels Dossche
62dc89d947
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-17224: UAF in importNode
2024-12-21 12:01:48 +01:00
Niels Dossche
61615d5673
Fix GH-17224: UAF in importNode
Wrong document pointer is used for the namespace copy.

Closes GH-17230.
2024-12-21 12:01:22 +01:00
Máté Kocsis
7e45e57d8f
Suppress deprecation notices when ext/dom properties are accessed by the get_debug_info handler (#15530) 2024-08-23 10:39:11 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Bnayard
6d9a74cde0 ext/dom: Use standard wording for ValueError 2024-08-21 21:12:17 +01:00
Máté Kocsis
587110c5bf
Deprecate Soft-deprecated DOMDocument and DOMEntity properties (#15369)
RFC: https://wiki.php.net/rfc/deprecations_php_8_4#formally_deprecate_soft-deprecated_domdocument_and_domentity_properties
2024-08-13 12:39:20 +01:00
Niels Dossche
0122be574a
Simplify document standalone setter (#15320)
The logic was very weird as it just should check whether the boolean is
true or not. And in fact the code is equivalent because zval_get_long()
will only return 0/1 because the type is a bool, and ZEND_NORMALIZE_BOOL
won't change that value.
2024-08-10 15:35:04 +02:00
Niels Dossche
a0c29f0889
Use unsigned int instead of int for refcount for libxml objects (#15247) 2024-08-05 22:04:24 +02:00
Niels Dossche
80a4783d25
Deduplicate NULL checks in ext/dom (#15015)
This introduces a new helper php_dom_create_nullable_object() that does
the NULL check and puts NULL in return_value. Otherwise it runs
php_dom_create_object(). This deduplicates a bit of code.
2024-07-18 21:20:03 +02:00
Niels Dossche
6980eba863
Support templated content
The template element in HTML 5 is special in the sense that it does not
add its contents into the DOM tree, but instead keeps them in a separate
shadow DOM document fragment. Interacting with the DOM tree cannot touch
the elements in the document fragment.

Closes GH-14906.
2024-07-15 11:10:51 +02:00
Niels Dossche
8825235348
Reapply "Stop using reserved names in dom"
This reverts commit dda96768ec.
2024-07-08 17:27:39 +02:00
Niels Dossche
dda96768ec
Revert "Stop using reserved names in dom"
This reverts commit 013bc53f0c.

This somehow breaks the Windows build. Will investigate later.
2024-07-08 16:07:32 +02:00
Niels Dossche
013bc53f0c Stop using reserved names in dom 2024-07-08 06:09:04 -07:00
Niels Dossche
ecf0bb0fd1
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS
  Backport libxml2 2.13.2 fixes (#14816)
2024-07-04 15:37:35 +02:00
Niels Dossche
4fe821311c
Backport libxml2 2.13.2 fixes (#14816)
Backproted from https://github.com/php/php-src/pull/14789
2024-07-04 15:29:50 +02:00
Niels Dossche
85705eda71 Fix compilation on libxml2 2.13 2024-07-03 10:34:46 -07:00
Niels Dossche
bcdba83cbb
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-14702: DOMDocument::xinclude() crash
2024-06-28 22:29:03 +02:00
Niels Dossche
0a1f51deb3
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-14702: DOMDocument::xinclude() crash
2024-06-28 22:22:12 +02:00
Niels Dossche
42908f9f68
Fix GH-14702: DOMDocument::xinclude() crash
The xinclude code from libxml removes the fallback node,
but the fallback node is still reference via $fallback.
The solution is to detach the nodes that are going to be removed in
advance.

Closes GH-14704.
2024-06-28 22:21:12 +02:00
Arnaud Le Blanc
11accb5cdf
Preferably include from build dir (#13516)
* Include from build dir first

This fixes out of tree builds by ensuring that configure artifacts are included
from the build dir.

Before, out of tree builds would preferably include files from the src dir, as
the include path was defined as follows (ignoring includes from ext/ and sapi/) :

    -I$(top_builddir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/main
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM
    -I$(top_builddir)/

As a result, an out of tree build would include configure artifacts such as
`main/php_config.h` from the src dir.

After this change, the include path is defined as follows:

    -I$(top_builddir)/main
    -I$(top_builddir)
    -I$(top_srcdir)/main
    -I$(top_srcdir)
    -I$(top_builddir)/TSRM
    -I$(top_builddir)/Zend
    -I$(top_srcdir)/Zend
    -I$(top_srcdir)/TSRM

* Fix extension include path for out of tree builds

* Include config.h with the brackets form

`#include "config.h"` searches in the directory containing the including-file
before any other include path. This can include the wrong config.h when building
out of tree and a config.h exists in the source tree.

Using `#include <config.h>` uses exclusively the include path, and gives
priority to the build dir.
2024-06-26 00:26:43 +02:00
Niels Dossche
a068a9a5bb Make XMLDocument::xinclude() return values and error conditions sane
See https://wiki.php.net/rfc/dom_additions_84#api_amendments
2024-06-24 12:36:35 -07:00
Niels Dossche
8dc2391bae
Fix bug #79701: getElementById does not correctly work with duplicate definitions
This is a long standing bug: IDs aren't properly tracked causing either
outdated or plain incorrect results from getElementById.

This PR implements a pragmatic solution in which we still try to use the
ID lookup table to a degree, but only as a performance boost not as a
"single source of truth". Full details are explained in the
getElementById code.

Closes GH-14349.
2024-06-01 12:55:05 +02:00
Niels Dossche
f90a32c9bf
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix build
2024-05-29 18:50:13 +02:00
Niels Dossche
edc130910f
Fix build 2024-05-29 18:50:07 +02:00
Niels Dossche
acfa564e72
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix bug #47925 again (#14348)
  Fix GH-14343: Memory leak in xml and dom (#14347)
2024-05-29 17:52:00 +02:00
Niels Dossche
fe0214bb55
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix bug #47925 again (#14348)
  Fix GH-14343: Memory leak in xml and dom (#14347)
2024-05-29 17:51:47 +02:00
Niels Dossche
88ff32a25b
Fix GH-14343: Memory leak in xml and dom (#14347)
If there is no root, the namespace cannot be attached to it,
so we have to attach it to the old list.

This isn't a problem in "new DOM" because namespaces are managed in a
separate structure there.
2024-05-29 17:49:07 +02:00
Niels Dossche
0c490ade0d Handle dumping document to file 2024-05-11 18:09:39 +02:00
Niels Dossche
44485892df Factor out all common code for XML serialization and merge common paths 2024-05-11 18:09:39 +02:00
Niels Dossche
6e7adb3c48
Update ext/dom names after policy change (#14171) 2024-05-09 10:40:53 +02:00
Niels Dossche
22a113b99c
Try to use an interned local name in createElementNS (#14127) 2024-05-04 13:59:43 +02:00
Niels Dossche
d24a04bba8
Use fast ZPP in very commonly used DOM functions (#14077)
Start using fast ZPP in very commonly used DOM functions, and also try
to unify some branches by using RETURN_BOOL where appropriate.
2024-04-30 17:29:33 +02:00
Niels Dossche
ed916214c4
Avoid additional allocation in Document\createElementNS (#14071)
For the following benchmark code:
```php
$dom = DOM\XMLDocument::createEmpty();
for ($i = 0; $i < 1000*100; $i++) $dom->createElementNS("urn:a", "thisisaveryverylongname");
```

We obtain the following on an i7-4790:
```
Benchmark 1: ./sapi/cli/php bench.php
  Time (mean ± σ):      34.5 ms ±   1.2 ms    [User: 31.4 ms, System: 2.9 ms]
  Range (min … max):    32.4 ms …  39.3 ms    84 runs

Benchmark 2: ./sapi/cli/php_old bench.php
  Time (mean ± σ):      36.6 ms ±   1.6 ms    [User: 33.6 ms, System: 2.9 ms]
  Range (min … max):    34.3 ms …  45.3 ms    80 runs

Summary
  ./sapi/cli/php bench.php ran
    1.06 ± 0.06 times faster than ./sapi/cli/php_old bench.php
```
2024-04-29 08:39:44 +02:00
Niels Dossche
3626e2d552
Get rid of remaining usages of zval_try_get_string() (#14041)
This isn't necessary because the cases where we use it will always
succeed because the properties always have the type string|null.
2024-04-24 23:47:10 +02:00
Niels Dossche
539d8d9259 Use common helper macro for getting the node in property handlers 2024-03-10 11:08:46 +01:00
Niels Dossche
d57e7a920b Use BAD_CAST consistently 2024-03-10 11:08:46 +01:00
Niels Dossche
37791d6f92 Cleanup buffer handling in saveHTML 2024-03-10 11:08:46 +01:00
Niels Dossche
6c55513e33 Use true instead of 1 with php_dom_throw_error 2024-03-10 11:08:46 +01:00
Niels Dossche
63bb04e5bf Simplify DOM_RET_OBJ macro 2024-03-10 11:08:46 +01:00
Niels Dossche
14b6c981c3
[RFC] Add a way to opt-in ext/dom spec compliance (#13031)
RFC: https://wiki.php.net/rfc/opt_in_dom_spec_compliance
2024-03-09 16:56:00 +01:00
Niels Dossche
035a5fdf8c
Add LIBXML_RECOVER (#13504)
Setting the recovery option by using a hardcoded value (1) worked
already for SimpleXML. For DOM, a small change is necessary because
otherwise the recover field overwrites the recovery option.

From a quick search on GitHub [1] it looks like this won't clash with
existing PHP code as no one seems to define (or use) a constant with
such a name.

[1] https://github.com/search?q=LIBXML_RECOVER+language%3APHP&type=code&l=PHP
2024-02-25 21:03:37 +01:00
Niels Dossche
f420ea84aa Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix crashes with entity references and predefined entities
  Fix crash in adoptNode with attribute references
2023-12-23 17:01:28 +01:00
Niels Dossche
8e8d5ce240 Fix crash in adoptNode with attribute references
I forgot to also update the document reference of attributes, so when
there is no document reference anymore from a variable, but still an
attribute, this can crash. Fix it by also updating the document
references for attributes.

Closes GH-13002.
2023-12-23 16:58:11 +01:00
Niels Dossche
82baeeb196
Some more DOM testing and code style updates (#12933) 2023-12-16 13:46:08 +01:00