Problem/Motivation

Class: Drupal\search_api\Plugin\search_api\processor\HtmlFilter
Line: 225

If the preg_match call returns FALSE, the Array element $m[1] does not exist.

This results in a warning (with PHP errors in "strict" mode) that causes a recursion that exhausts the memory available to PHP.

Proposed resolution

Check if preg_match returns FALSE.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gwagroves created an issue. See original summary.

alan-ps’s picture

It looks like we can get this error if html tags does not used. This text can cause a problem described in this issue: Test < Test 2

The simplest solution is to add a check like this (line 221 in src/Plugin/search_api/processor/HtmlFilter.php)

-      preg_match('#^(/?)([-:_a-zA-Z0-9]+)#', $text, $m);
+      if (!preg_match('#^(/?)([-:_a-zA-Z0-9]+)#', $text, $m)) {
+        continue;
+      }

But I'm not sure whether this is correct. Probably, the problem is more deeper :(

drunken monkey’s picture

Thanks for your analysis, alan-ps. It indeed seems like this can only happen if the analyzed field value isn't proper/valid HTML.
The easiest fix on your side, @gwagroves, is therefore to only enable that filter on fields that actually contain HTML.

However, I guess we really shouldn't produce warnings even in this case, but try to ignore the invalid character (though this won't work that well if there is no whitespace after the unescaped "<" character).

Patch with fix and test attached. Please test!

The last submitted patch, 3: 2821445-3--html_filter_fault_tolerance--tests_only.patch, failed testing.

alan-ps’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Tested and works fine for me as well.

  • drunken monkey committed 5ec57ce on 8.x-1.x
    Issue #2821445 by drunken monkey: Fixed warning in HTML filter for non-...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Good to hear, thanks for testing and reviewing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.