Closed (fixed)
Project:
Search API
Version:
8.x-1.x-dev
Component:
Plugins
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Feb 2022 at 10:26 UTC
Updated:
29 Jun 2023 at 12:23 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dieterholvoet commentedComment #3
bonrita commentedAlso see: https://www.drupal.org/project/search_api/issues/3115343#comment-14269782
Comment #4
dieterholvoet commentedThanks for sharing, but I was already aware. That issue is linked below Related issues.
Comment #5
dieterholvoet commentedI was able to narrow down the issue, it can be reproduced by passing the following string:
through the regex in
Highlight::highlightField:The problem is invalid HTML, so I think a possible solution would be to fix any broken markup before passing it to that regex. We could also update the regex, but I'm afraid that regex is too complex for me.
Comment #7
dieterholvoet commentedI added a fix and a test. I also attached a patch for inclusion in Composer projects.
Comment #8
drunken monkeyThanks for reporting this issue and already providing a patch – very nice work!
Thanks, especially, that you even provided a test already! The test, however, is slightly off, as it’s actually not the excerpt that’s making problems (as we already strip all tags from the tags before creating the excerpt) but fields highlighting.
I therefore adapted the test slightly to better tell what’s actually being tested.
The problem itself seems to come from excessive backtracking, and therefore seems only slightly related to invalid HTML. Therefore, I think we’re better off trying to fix the regex to not need as much backtracking anymore. Please see/test/review my attached revision and tell me what you think.
Anyways, thanks again for your nice work on this!
(Unfortunately, the test bot doesn’t work for MRs in this project, so please use the old patch workflow instead.)
Comment #10
dieterholvoet commentedThese changes look good, thanks for the feedback!
Comment #12
drunken monkeyGood to hear, thanks for reporting back!
Committed. Thanks again!
Comment #14
bonsaipuppyI might be misinterpreting the use of the preg_split, but as far as i understand from the source code it's supposed to throw away any html tags, opening and closing ones, to just leave the text inside those to highlight in.
then the regex in the patch won't work properly for nodes with attributes having quoted values.
check it out on regex101: https://regex101.com/r/w0OSao/1