sulu: [MarkupBundle] preg_match_all(): Argument #2 ($subject) must be of type string, array given

Q A
Sulu Version 2.5.8
PHP Version PHP 8.1

Actual Behavior

An admin user tries to delete a page but the deletion process fails with the following error in the logs:

[2023-08-17T21:24:44.183109+02:00] php.CRITICAL: Uncaught Error: preg_match_all(): Argument #2 ($subject) must be of type string, array given {"exception":"[object] (TypeError(code: 0): preg_match_all(): Argument #2 ($subject) must be of type string, array given at /var/www/vendor/sulu/sulu/src/Sulu/Bundle/MarkupBundle/Markup/HtmlTagExtractor.php:40)"} []

Expected Behavior

Page deletion should work.

Steps to Reproduce

Since the deletion of other pages works fine, I assume something is odd with that specific page. So it’s not a general bug in Sulu. Still, it should be fixed somehow to allow “defect” pages to be deleted.

Possible Solutions

My current “quick fix” works as follows:

  1. In Sulu\Bundle\MarkupBundle\Markup\HtmlTagExtractor::count() I added the following check:
if (!is_string($html)) {
    return 0;
}
  1. In Sulu\Bundle\MarkupBundle\Markup\HtmlTagExtractor::extract() I added the following check:
if (!is_string($html)) {
    return [];
}

After applying the patch, the page deletion for the specific page is working again. If you feel the patch outlined above makes sense, let me know and I prepare a PR.

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 19 (19 by maintainers)

Most upvoted comments

@shochdoerfer if you want you can tackle a Merge Request with the suggestion in: https://github.com/sulu/sulu/issues/7140#issuecomment-1685795306 for 2.4

Don’t see how this should be releated how the Document is rendered on the Website. It need to be more when a document is modified not when it is rendered. As said most common case would be if you have a field in your templates which has the same name but another type. But for that case you first need to find out which text_editor field is effect by the bug and then check what other fields exist with the same name. Another error could by if the type was changed in the past without adding phpcr migrations for it to the project.

What is the error on accessing it? Also would look at the phpcr-node itself via the doctrine:phpcr:shell.