Detect exact names during autocompletion

Do not recognize substrings of strings as the full string in searchMatch.

fixes #9633
This commit is contained in:
Matthias Jentsch 2015-08-21 13:34:03 +02:00
parent a0b559f032
commit 2d9d3a0788
1 changed files with 4 additions and 24 deletions

View File

@ -273,30 +273,10 @@ class Loader
protected function searchMatch($needle, $haystack)
{
$stack = $haystack;
$search = $needle;
$this->lastSuggestions = array();
while (strlen($search) > 0) {
$len = strlen($search);
foreach ($stack as & $s) {
$s = substr($s, 0, $len);
}
$res = array_keys($stack, $search, true);
if (count($res) === 1) {
$found = $haystack[$res[0]];
if (substr($found, 0, strlen($needle)) === $needle) {
return $found;
} else {
return false;
}
} elseif (count($res) > 1) {
foreach ($res as $key) {
$this->lastSuggestions[] = $haystack[$key];
}
return false;
}
$search = substr($search, 0, -1);
$this->lastSuggestions = preg_grep(sprintf('/^%s.*$/', preg_quote($needle, '/')), $haystack);
$match = array_search($needle, $haystack, true);
if (false !== $match) {
return $haystack[$match];
}
return false;
}