preg_replace errors breaks the Util::removeHtmlComments() function.

Created on 18 September 2025, 24 days ago

Problem/Motivation

In Util::removeHtmlComments(), there's a preg_replace call to remove HTML comments. When preg_replace have an error, it'll return a null value.

Since the preg_replace return value if fed directly in the trim function, we get this error message : TypeError: trim(): Argument #1 ($string) must be of type string, null given in trim() (line 68 of modules/contrib/sdc_display/src/Util.php).

Steps to reproduce

In our case, we have a CKEditor field where the content editor decided to hive a huge part of the page by using HTML comments. This triggered a PREG_JIT_STACKLIMIT_ERROR from the preg_replace function.

Proposed resolution

Refactor that function a bit so it can handle preg_replace errors. I think that any preg_replace errors could be raised as warnings in the Drupal logs, and we'd simply return the input untouched.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada arakwar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024