Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 296300

Search with a special character throws preg_replace() error on excerpts with HTML entities

$
0
0

Error encountered:
Warning: preg_replace(): Compilation failed: invalid UTF-8 string at offset 5157 in search_excerpt() (line 1256 of /home/example/www/modules/search/search.module).

What is happening:
Currently in a search when there is a special character on its own (therefore counted as a key) it gets replaced with a space in the search_simplify function and stored as the $simplified_key as the space character. When an HTML entity gets run through that function and gets replaced by a space, this counts as a match for the $simplified_key in the search_simplify_excerpt_match function. The position of this match results in the HTML entity character being returned from the non-simplified text as the U+FFFD replacement character (�). This gets returned back to the search_excerpt function as a keyword into the $foundkeys array.
While trying to highlight all found keywords at the end of the search_excerpt function it then throws an error when passing in the HTML entity key as the U+FFFD replacement character (�) into the preg_replace() function.

Reproduce the bug:
I am able to reproduce this issue using a fresh install on simplytest.me following the below steps:
1. Drupal core v7.52-dev install (also tested on v7.51)
2. Add content - type Basic Page in my reproduction
3. Add text in the body to search
4. Replace a space in the body with   between two words - one of which I will search for (i.e., This is a test page.)
5. Save the content
6. Re-index the site via manually running the cron maintenance task
7. Perform a search with the following text: "test !"
8. Receive search results with the page containing   with no excerpt and the preg_replace() error at the top of the page


Viewing all articles
Browse latest Browse all 296300


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>