Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2821445-3--html_filter_fault_tolerance.patch | 1.84 KB | drunken monkey |
| |||
#3 | 2821445-3--html_filter_fault_tolerance--tests_only.patch | 546 bytes | drunken monkey |
Comments
Comment #2
alan-ps CreditAttribution: alan-ps commentedIt 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)
But I'm not sure whether this is correct. Probably, the problem is more deeper :(
Comment #3
drunken monkeyThanks 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!
Comment #5
alan-ps CreditAttribution: alan-ps commentedLooks good. Tested and works fine for me as well.
Comment #7
drunken monkeyGood to hear, thanks for testing and reviewing!
Committed.