In some cases the processor method highlightField() returns wrong output

For example

When input is:
<a href="/education/glossary/investment-underwriting-agreement" hreflang="pl">investment underwriting agreement</a>
it produces output like this:
<a href="/education/glossary/investment-underwriting-<strong>agreement</strong>" hreflang="pl">investment underwriting <strong>agreement</strong>

Maybe the problem with regex?

https://onlinephp.io/c/4e103
See also this comment https://www.drupal.org/project/search_api/issues/3264239#comment-15129743

Comments

jlukasie created an issue. See original summary.

jlukasie’s picture

Issue summary: View changes
drunken monkey’s picture

Version: 8.x-1.29 » 8.x-1.x-dev
Component: General code » Plugins
Status: Active » Needs review
StatusFileSize
new1.17 KB

Thanks a lot for reporting this problem.
I could reproduce it, and writing a regression test for it is also pretty simple, see attached.

However, I cannot really see where the regular expression goes wrong. Do you have a proposed fix for this problem, a regular expression that actually matched complete HTML tags even if they have attributes with values?

Status: Needs review » Needs work
drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new2.56 KB
new2.59 KB

Maybe just simplify the tag contents expression instead of trying to match individual attributes? I guess we used the current regular expression to avoid problems in case of invalid HTML, but should hopefully be a minor problem at this point.

jlukasie’s picture

Thanks, I think You are right. The simpler expression is the better for future maintenance.
Invalid HTML should be no big problem at the moment.

  • drunken monkey committed 3724d3dc on 8.x-1.x
    Issue #3390450 by drunken monkey: Fixed highlighting of HTML field...
drunken monkey’s picture

Status: Needs review » Fixed

Thanks for the feedback!
Committed.

Status: Fixed » Closed (fixed)

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