aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-08-02 15:37:43 +0200
committerGitHub <noreply@github.com>2016-08-02 15:37:43 +0200
commit58f0660f80b8f6fa29f7ffa99a33edc76d841850 (patch)
tree2ab5f36db51fb71188c4d978682027f8e1a7e707
parentefc0c865ba914e75a6c3c9220450d13f752c7afa (diff)
parent9866b40814a120f1a019f9f2c8ef66f44e1ddfcb (diff)
downloadShaarli-58f0660f80b8f6fa29f7ffa99a33edc76d841850.tar.gz
Shaarli-58f0660f80b8f6fa29f7ffa99a33edc76d841850.tar.zst
Shaarli-58f0660f80b8f6fa29f7ffa99a33edc76d841850.zip
Merge pull request #618 from ArthurHoaro/tagclean
Better whitespace handling in tags
-rw-r--r--application/LinkDB.php4
-rw-r--r--tests/LinkDBTest.php4
-rw-r--r--tests/utils/ReferenceLinkDB.php2
3 files changed, 7 insertions, 3 deletions
diff --git a/application/LinkDB.php b/application/LinkDB.php
index 929a6b0f..d80434bf 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -291,7 +291,7 @@ You use the community supported version of the original Shaarli project, by Seba
291 291
292 // Remove private tags if the user is not logged in. 292 // Remove private tags if the user is not logged in.
293 if (! $this->_loggedIn) { 293 if (! $this->_loggedIn) {
294 $link['tags'] = preg_replace('/(^| )\.[^($| )]+/', '', $link['tags']); 294 $link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']);
295 } 295 }
296 296
297 // Do not use the redirector for internal links (Shaarli note URL starting with a '?'). 297 // Do not use the redirector for internal links (Shaarli note URL starting with a '?').
@@ -442,7 +442,7 @@ You use the community supported version of the original Shaarli project, by Seba
442 $tags = array(); 442 $tags = array();
443 $caseMapping = array(); 443 $caseMapping = array();
444 foreach ($this->_links as $link) { 444 foreach ($this->_links as $link) {
445 foreach (explode(' ', $link['tags']) as $tag) { 445 foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) {
446 if (empty($tag)) { 446 if (empty($tag)) {
447 continue; 447 continue;
448 } 448 }
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index 46956f20..31306069 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -317,6 +317,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
317 '-exclude' => 1, 317 '-exclude' => 1,
318 '.hidden' => 1, 318 '.hidden' => 1,
319 'hashtag' => 2, 319 'hashtag' => 2,
320 'tag1' => 1,
321 'tag2' => 1,
322 'tag3' => 1,
323 'tag4' => 1,
320 ), 324 ),
321 self::$privateLinkDB->allTags() 325 self::$privateLinkDB->allTags()
322 ); 326 );
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php
index fe16baac..fcc7a4f9 100644
--- a/tests/utils/ReferenceLinkDB.php
+++ b/tests/utils/ReferenceLinkDB.php
@@ -75,7 +75,7 @@ class ReferenceLinkDB
75 '', 75 '',
76 1, 76 1,
77 '20121206_182539', 77 '20121206_182539',
78 'dev cartoon' 78 'dev cartoon tag1 tag2 tag3 tag4 '
79 ); 79 );
80 } 80 }
81 81