aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/LinkFilter.php2
-rw-r--r--application/Utils.php13
-rw-r--r--index.php10
-rw-r--r--tests/UtilsTest.php14
-rw-r--r--tpl/feed.atom.html2
-rw-r--r--tpl/feed.rss.html2
6 files changed, 36 insertions, 7 deletions
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
348 $tagsOut = $casesensitive ? $tags : mb_convert_case($tags, MB_CASE_LOWER, 'UTF-8'); 348 $tagsOut = $casesensitive ? $tags : mb_convert_case($tags, MB_CASE_LOWER, 'UTF-8');
349 $tagsOut = str_replace(',', ' ', $tagsOut); 349 $tagsOut = str_replace(',', ' ', $tagsOut);
350 350
351 return array_values(array_filter(explode(' ', trim($tagsOut)), 'strlen')); 351 return preg_split('/\s+/', $tagsOut, -1, PREG_SPLIT_NO_EMPTY);
352 } 352 }
353} 353}
354 354
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)
257 257
258 return str_shuffle(substr(hash_hmac('sha512', uniqid($salt), $username), 10, 12)); 258 return str_shuffle(substr(hash_hmac('sha512', uniqid($salt), $username), 10, 12));
259} 259}
260
261/**
262 * Trim string, replace sequences of whitespaces by a single space.
263 * PHP equivalent to `normalize-space` XSLT function.
264 *
265 * @param string $string Input string.
266 *
267 * @return mixed Normalized string.
268 */
269function normalize_spaces($string)
270{
271 return preg_replace('/\s{2,}/', ' ', trim($string));
272}
diff --git a/index.php b/index.php
index a970e29f..bb1debd3 100644
--- a/index.php
+++ b/index.php
@@ -1601,8 +1601,8 @@ function renderPage($conf, $pluginManager, $LINKSDB)
1601function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager) 1601function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
1602{ 1602{
1603 // Used in templates 1603 // Used in templates
1604 $searchtags = !empty($_GET['searchtags']) ? escape($_GET['searchtags']) : ''; 1604 $searchtags = !empty($_GET['searchtags']) ? escape(normalize_spaces($_GET['searchtags'])) : '';
1605 $searchterm = !empty($_GET['searchterm']) ? escape($_GET['searchterm']) : ''; 1605 $searchterm = !empty($_GET['searchterm']) ? escape(normalize_spaces($_GET['searchterm'])) : '';
1606 1606
1607 // Smallhash filter 1607 // Smallhash filter
1608 if (! empty($_SERVER['QUERY_STRING']) 1608 if (! empty($_SERVER['QUERY_STRING'])
@@ -1649,7 +1649,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
1649 } else { 1649 } else {
1650 $link['updated_timestamp'] = ''; 1650 $link['updated_timestamp'] = '';
1651 } 1651 }
1652 $taglist = explode(' ', $link['tags']); 1652 $taglist = preg_split('/\s+/', $link['tags'], -1, PREG_SPLIT_NO_EMPTY);
1653 uasort($taglist, 'strcasecmp'); 1653 uasort($taglist, 'strcasecmp');
1654 $link['taglist'] = $taglist; 1654 $link['taglist'] = $taglist;
1655 // Check for both signs of a note: starting with ? and 7 chars long. 1655 // Check for both signs of a note: starting with ? and 7 chars long.
@@ -1949,8 +1949,8 @@ function install($conf)
1949 $conf->set( 1949 $conf->set(
1950 'api.secret', 1950 'api.secret',
1951 generate_api_secret( 1951 generate_api_secret(
1952 $this->conf->get('credentials.login'), 1952 $conf->get('credentials.login'),
1953 $this->conf->get('credentials.salt') 1953 $conf->get('credentials.salt')
1954 ) 1954 )
1955 ); 1955 );
1956 try { 1956 try {
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
index 0cf9a921..c885f552 100644
--- a/tests/UtilsTest.php
+++ b/tests/UtilsTest.php
@@ -253,7 +253,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase
253 is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=') 253 is_session_id_valid('c0ZqcWF3VFE2NmJBdm1HMVQ0ZHJ3UmZPbTFsNGhkNHI=')
254 ); 254 );
255 } 255 }
256 256
257 /** 257 /**
258 * Test generateSecretApi. 258 * Test generateSecretApi.
259 */ 259 */
@@ -270,4 +270,16 @@ class UtilsTest extends PHPUnit_Framework_TestCase
270 $this->assertFalse(generate_api_secret('', '')); 270 $this->assertFalse(generate_api_secret('', ''));
271 $this->assertFalse(generate_api_secret(false, false)); 271 $this->assertFalse(generate_api_secret(false, false));
272 } 272 }
273
274 /**
275 * Test normalize_spaces.
276 */
277 public function testNormalizeSpace()
278 {
279 $str = ' foo bar is important ';
280 $this->assertEquals('foo bar is important', normalize_spaces($str));
281 $this->assertEquals('foo', normalize_spaces('foo'));
282 $this->assertEquals('', normalize_spaces(''));
283 $this->assertEquals(null, normalize_spaces(null));
284 }
273} 285}
diff --git a/tpl/feed.atom.html b/tpl/feed.atom.html
index ad7dd935..49798e85 100644
--- a/tpl/feed.atom.html
+++ b/tpl/feed.atom.html
@@ -6,6 +6,8 @@
6 <updated>{$last_update}</updated> 6 <updated>{$last_update}</updated>
7 {/if} 7 {/if}
8 <link rel="self" href="{$self_link}#" /> 8 <link rel="self" href="{$self_link}#" />
9 <link rel="search" type="application/opensearchdescription+xml" href="{$index_url}?do=opensearch#"
10 title="Shaarli search - {$shaarlititle}" />
9 {loop="$feed_plugins_header"} 11 {loop="$feed_plugins_header"}
10 {$value} 12 {$value}
11 {/loop} 13 {/loop}
diff --git a/tpl/feed.rss.html b/tpl/feed.rss.html
index 73791f63..ee3fef88 100644
--- a/tpl/feed.rss.html
+++ b/tpl/feed.rss.html
@@ -8,6 +8,8 @@
8 <copyright>{$index_url}</copyright> 8 <copyright>{$index_url}</copyright>
9 <generator>Shaarli</generator> 9 <generator>Shaarli</generator>
10 <atom:link rel="self" href="{$self_link}" /> 10 <atom:link rel="self" href="{$self_link}" />
11 <atom:link rel="search" type="application/opensearchdescription+xml" href="{$index_url}?do=opensearch#"
12 title="Shaarli search - {$shaarlititle}" />
11 {loop="$feed_plugins_header"} 13 {loop="$feed_plugins_header"}
12 {$value} 14 {$value}
13 {/loop} 15 {/loop}