From a6e6b2e96b3bb174a656b71149808add7d488b39 Mon Sep 17 00:00:00 2001 From: webchick Date: Sat, 24 Mar 2012 00:36:00 -0600 Subject: Issue #1335388 by wojtha: Fixed Warning: strpos(): Empty delimiter in search_simplify_excerpt_match(). --- modules/search/search.module | 5 +++++ modules/search/search.test | 15 +++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'modules/search') diff --git a/modules/search/search.module b/modules/search/search.module index 915c96fb2..33cd77eae 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -1293,6 +1293,11 @@ function search_simplify_excerpt_match($key, $text, $offset, $boundary) { $simplified_key = search_simplify($key); $simplified_text = search_simplify($text); + // Return immediately if simplified key or text are empty. + if (!$simplified_key || !$simplified_text) { + return FALSE; + } + // Check if we have a match after simplification in the text. if (!preg_match('/' . $boundary . $simplified_key . $boundary . '/iu', $simplified_text, $match, PREG_OFFSET_CAPTURE, $offset)) { return FALSE; diff --git a/modules/search/search.test b/modules/search/search.test index ca1dd24a3..26c663e71 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -1639,6 +1639,21 @@ class SearchExcerptTestCase extends DrupalUnitTestCase { $result = preg_replace('| +|', ' ', search_excerpt('"abc def"', $text)); $this->assertTrue(strpos($result, 'abc,def') !== FALSE, 'Phrase with keyword simplified into two separate words is highlighted with simplified match'); + + // Test phrases with characters which are being truncated. + $result = preg_replace('| +|', ' ', search_excerpt('"ipsum _"', $text)); + $this->assertTrue(strpos($result, 'ipsum ') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part containing "_" is ignored.'); + + $result = preg_replace('| +|', ' ', search_excerpt('"ipsum 0000"', $text)); + $this->assertTrue(strpos($result, 'ipsum ') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part "0000" is ignored.'); + + // Test combination of the valid keyword and keyword containing only + // characters which are being truncated during simplification. + $result = preg_replace('| +|', ' ', search_excerpt('ipsum _', $text)); + $this->assertTrue(strpos($result, 'ipsum') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "_" is ignored.'); + + $result = preg_replace('| +|', ' ', search_excerpt('ipsum 0000', $text)); + $this->assertTrue(strpos($result, 'ipsum') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "0000" is ignored.'); } } -- cgit v1.2.3