Loading CHANGELOG.txt +1 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3390450 by drunken monkey: Fixed highlighting of HTML field values. - #3370934 by drunken monkey: Fixed missing log messages in Drush. - #3390686 by FeyP, drunken monkey: Fixed RenderedItem processor to always switch back to previous account. Loading src/Plugin/search_api/processor/Highlight.php +19 −1 Original line number Diff line number Diff line Loading @@ -657,7 +657,25 @@ class Highlight extends ProcessorPluginBase implements PluginFormInterface { protected function highlightField($text, array $keys, $html = TRUE) { $text = "$text"; if ($html) { $texts = preg_split('#(\s*(?:</?[[:alpha:]](?:[^>"\']*+|"[^"]*+"|\'[^\']*+\')*+>)+\s*)#i', $text, -1, PREG_SPLIT_DELIM_CAPTURE); $regex = <<<'REGEX' % ( # Capturing group around the whole expression, so # PREG_SPLIT_DELIM_CAPTURE works correctly \s*+ # Optional leading whitespace (possessive since backtracking # would make no sense here) (?: # One or more HTML tags < # Start of HTML tag /? # Could be a closing tag [[:alpha:]] # Tag names always start with a letter [^>]* # Anything except the angle bracket closing the tag > # End of HTML tag )+ # End: One or more HTML tags \s* # Optional trailing whitespace ) # End: Capturing group %ix REGEX; $texts = preg_split($regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE); if ($texts === FALSE) { $args = [ '%error_num' => preg_last_error(), Loading tests/src/Unit/Processor/HighlightTest.php +16 −0 Original line number Diff line number Diff line Loading @@ -1209,6 +1209,22 @@ END; ]; } /** * Provides a regression test for bug #3390450. * * The effect of the bug was undesired highlighting of HTML attribute values. * * @see https://www.drupal.org/node/3390450 */ public function testRegressionBug3390450(): void { $method = new \ReflectionMethod($this->processor, 'highlightField'); $method->setAccessible(TRUE); $text = '<h1 title="agreement">Main</h1><a href="/underwriting-agreement">investment underwriting agreement</a>'; $excerpt = $method->invoke($this->processor, $text, ['agreement']); $expected = '<h1 title="agreement">Main</h1><a href="/underwriting-agreement">investment underwriting <strong>agreement</strong></a>'; $this->assertEquals($expected, $excerpt); } /** * Tests field highlighting with a result set that has some highlighting data. */ Loading Loading
CHANGELOG.txt +1 −0 Original line number Diff line number Diff line Search API 1.x, dev (xxxx-xx-xx): --------------------------------- - #3390450 by drunken monkey: Fixed highlighting of HTML field values. - #3370934 by drunken monkey: Fixed missing log messages in Drush. - #3390686 by FeyP, drunken monkey: Fixed RenderedItem processor to always switch back to previous account. Loading
src/Plugin/search_api/processor/Highlight.php +19 −1 Original line number Diff line number Diff line Loading @@ -657,7 +657,25 @@ class Highlight extends ProcessorPluginBase implements PluginFormInterface { protected function highlightField($text, array $keys, $html = TRUE) { $text = "$text"; if ($html) { $texts = preg_split('#(\s*(?:</?[[:alpha:]](?:[^>"\']*+|"[^"]*+"|\'[^\']*+\')*+>)+\s*)#i', $text, -1, PREG_SPLIT_DELIM_CAPTURE); $regex = <<<'REGEX' % ( # Capturing group around the whole expression, so # PREG_SPLIT_DELIM_CAPTURE works correctly \s*+ # Optional leading whitespace (possessive since backtracking # would make no sense here) (?: # One or more HTML tags < # Start of HTML tag /? # Could be a closing tag [[:alpha:]] # Tag names always start with a letter [^>]* # Anything except the angle bracket closing the tag > # End of HTML tag )+ # End: One or more HTML tags \s* # Optional trailing whitespace ) # End: Capturing group %ix REGEX; $texts = preg_split($regex, $text, -1, PREG_SPLIT_DELIM_CAPTURE); if ($texts === FALSE) { $args = [ '%error_num' => preg_last_error(), Loading
tests/src/Unit/Processor/HighlightTest.php +16 −0 Original line number Diff line number Diff line Loading @@ -1209,6 +1209,22 @@ END; ]; } /** * Provides a regression test for bug #3390450. * * The effect of the bug was undesired highlighting of HTML attribute values. * * @see https://www.drupal.org/node/3390450 */ public function testRegressionBug3390450(): void { $method = new \ReflectionMethod($this->processor, 'highlightField'); $method->setAccessible(TRUE); $text = '<h1 title="agreement">Main</h1><a href="/underwriting-agreement">investment underwriting agreement</a>'; $excerpt = $method->invoke($this->processor, $text, ['agreement']); $expected = '<h1 title="agreement">Main</h1><a href="/underwriting-agreement">investment underwriting <strong>agreement</strong></a>'; $this->assertEquals($expected, $excerpt); } /** * Tests field highlighting with a result set that has some highlighting data. */ Loading