From b3051a6aae446e063c3b6fa4a6a600357a9f24af Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 20 Dec 2016 11:06:22 +0100 Subject: Fixes presence of empty tags for private tags and in search results * Private tags: make sure empty tags are properly filtered * Search results: * Use preg_split instead of function combination * Add normalize_spaces to remove extra whitespaces displaying empty tags search --- application/LinkFilter.php | 2 +- application/Utils.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'application') diff --git a/application/LinkFilter.php b/application/LinkFilter.php index daa6d9cc..57ebfd5c 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php @@ -348,7 +348,7 @@ class LinkFilter $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); } } diff --git a/application/Utils.php b/application/Utils.php index 62902341..35d65224 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -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)); +} -- cgit v1.2.3