[ticket/10423] Remove * from search or highlight string

PHPBB3-10423
This commit is contained in:
Oliver Schramm 2014-03-28 21:58:18 +01:00
parent 40ed3f6776
commit 02378e94e7
2 changed files with 7 additions and 5 deletions

View file

@ -574,9 +574,9 @@ if ($keywords || $author || $author_id || $search_id || $submit)
} }
// define some vars for urls // define some vars for urls
$hilit = implode('|', explode(' ', preg_replace('#\s+#u', ' ', str_replace(array('+', '-', '|', '(', ')', '"'), ' ', $keywords)))); // A single wildcard will destroy the search query
// Do not allow *only* wildcard being used for hilight $hilit = trim(preg_replace('#(?<=^|\s)\*(?=\s|$)#', '', str_replace(array('+', '-', '|', '(', ')', '&quot;'), ' ', $keywords)));
$hilit = (strspn($hilit, '*') === strlen($hilit)) ? '' : $hilit; $hilit = implode('|', explode(' ', preg_replace('#\s+#u', ' ', $hilit)));
$u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit))); $u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit)));
$u_show_results = '&amp;sr=' . $show_results; $u_show_results = '&amp;sr=' . $show_results;
@ -840,7 +840,8 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$hilit_array = array_filter(explode('|', $hilit), 'strlen'); $hilit_array = array_filter(explode('|', $hilit), 'strlen');
foreach ($hilit_array as $key => $value) 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_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
} }
$hilit = implode('|', $hilit_array); $hilit = implode('|', $hilit_array);

View file

@ -475,9 +475,10 @@ if ($hilit_words)
{ {
if (trim($word)) if (trim($word))
{ {
$word = preg_replace('#\s+#u', ' ', trim(preg_replace('#(?<=^|\s)\*(?=\s|$)#', '', $word)));
$word = str_replace('\*', '\w+?', preg_quote($word, '#')); $word = str_replace('\*', '\w+?', preg_quote($word, '#'));
$word = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $word); $word = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $word);
$highlight_match .= (($highlight_match != '') ? '|' : '') . $word; $highlight_match .= (($highlight_match != '' && $word != '') ? '|' : '') . $word;
} }
} }