From 02378e94e779bbd407ef86166884c00e32d152fc Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Fri, 28 Mar 2014 21:58:18 +0100 Subject: [PATCH] [ticket/10423] Remove * from search or highlight string PHPBB3-10423 --- phpBB/search.php | 9 +++++---- phpBB/viewtopic.php | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/phpBB/search.php b/phpBB/search.php index 0f13dbbfa0..43eb42514e 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -574,9 +574,9 @@ if ($keywords || $author || $author_id || $search_id || $submit) } // define some vars for urls - $hilit = implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')', '"'), ' ', $keywords)))); - // Do not allow *only* wildcard being used for hilight - $hilit = (strspn($hilit, '*') === strlen($hilit)) ? '' : $hilit; + // A single wildcard will destroy the search query + $hilit = trim(preg_replace('#(?<=^|\s)\*(?=\s|$)#', '', str_replace(array('+', '-', '|', '(', ')', '"'), ' ', $keywords))); + $hilit = implode('|', explode(' ', preg_replace('#\s+#u', ' ', $hilit))); $u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit))); $u_show_results = '&sr=' . $show_results; @@ -840,7 +840,8 @@ if ($keywords || $author || $author_id || $search_id || $submit) $hilit_array = array_filter(explode('|', $hilit), 'strlen'); foreach ($hilit_array as $key => $value) { - $hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($value, '#')); + $hilit_array[$key] = preg_replace('#\s+#u', ' ', trim(preg_replace('#(?<=^|\s)\*(?=\s|$)#', '', $value))); + $hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($hilit_array[$key], '#')); $hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]); } $hilit = implode('|', $hilit_array); diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index e08d6e1ef5..4c9302dbbe 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -475,9 +475,10 @@ if ($hilit_words) { if (trim($word)) { + $word = preg_replace('#\s+#u', ' ', trim(preg_replace('#(?<=^|\s)\*(?=\s|$)#', '', $word))); $word = str_replace('\*', '\w+?', preg_quote($word, '#')); $word = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $word); - $highlight_match .= (($highlight_match != '') ? '|' : '') . $word; + $highlight_match .= (($highlight_match != '' && $word != '') ? '|' : '') . $word; } }