Merge pull request #725 from ArthurHoaro/hotfix/privatetags-split
Fixes presence of empty tags for private tags and in search results
This commit is contained in:
commit
64497fb302
4 changed files with 30 additions and 5 deletions
|
@ -348,7 +348,7 @@ public static function tagsStrToArray($tags, $casesensitive)
|
|||
$tagsOut = $casesensitive ? $tags : mb_convert_case($tags, MB_CASE_LOWER, 'UTF-8');
|
||||
$tagsOut = str_replace(',', ' ', $tagsOut);
|
||||
|
||||
return array_values(array_filter(explode(' ', trim($tagsOut)), 'strlen'));
|
||||
return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,3 +257,16 @@ function generate_api_secret($username, $salt)
|
|||
|
||||
return str_shuffle(substr(hash_hmac('sha512', uniqid($salt), $username), 10, 12));
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim string, replace sequences of whitespaces by a single space.
|
||||
* PHP equivalent to `normalize-space` XSLT function.
|
||||
*
|
||||
* @param string $string Input string.
|
||||
*
|
||||
* @return mixed Normalized string.
|
||||
*/
|
||||
function normalize_spaces($string)
|
||||
{
|
||||
return preg_replace('/\s{2,}/', ' ', trim($string));
|
||||
}
|
||||
|
|
|
@ -1601,8 +1601,8 @@ function($a, $b) { return $a['order'] - $b['order']; }
|
|||
function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
|
||||
{
|
||||
// Used in templates
|
||||
$searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : '';
|
||||
$searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : '';
|
||||
$searchtags = !empty($_GET['searchtags']) ? escape(normalize_spaces($_GET['searchtags'])) : '';
|
||||
$searchterm = !empty($_GET['searchterm']) ? escape(normalize_spaces($_GET['searchterm'])) : '';
|
||||
|
||||
// Smallhash filter
|
||||
if (! empty($_SERVER['QUERY_STRING'])
|
||||
|
@ -1649,7 +1649,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
|
|||
} else {
|
||||
$link['updated_timestamp'] = '';
|
||||
}
|
||||
$taglist = explode(' ', $link['tags']);
|
||||
$taglist = preg_split('/\s+/', $link['tags'], -1, PREG_SPLIT_NO_EMPTY);
|
||||
uasort($taglist, 'strcasecmp');
|
||||
$link['taglist'] = $taglist;
|
||||
// Check for both signs of a note: starting with ? and 7 chars long.
|
||||
|
|
|
@ -270,4 +270,16 @@ public function testGenerateSecretApiInvalid()
|
|||
$this->assertFalse(generate_api_secret('', ''));
|
||||
$this->assertFalse(generate_api_secret(false, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test normalize_spaces.
|
||||
*/
|
||||
public function testNormalizeSpace()
|
||||
{
|
||||
$str = ' foo bar is important ';
|
||||
$this->assertEquals('foo bar is important', normalize_spaces($str));
|
||||
$this->assertEquals('foo', normalize_spaces('foo'));
|
||||
$this->assertEquals('', normalize_spaces(''));
|
||||
$this->assertEquals(null, normalize_spaces(null));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue