Skip to content

Commit

Permalink
Merge pull request #618 from ArthurHoaro/tagclean
Browse files Browse the repository at this point in the history
Better whitespace handling in tags
  • Loading branch information
virtualtam authored Aug 2, 2016
2 parents efc0c86 + 9866b40 commit 58f0660
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions application/LinkDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private function _readDB()

// Remove private tags if the user is not logged in.
if (! $this->_loggedIn) {
$link['tags'] = preg_replace('/(^| )\.[^($| )]+/', '', $link['tags']);
$link['tags'] = preg_replace('/(^|\s+)\.[^($|\s)]+\s*/', ' ', $link['tags']);
}

// Do not use the redirector for internal links (Shaarli note URL starting with a '?').
Expand Down Expand Up @@ -442,7 +442,7 @@ public function allTags()
$tags = array();
$caseMapping = array();
foreach ($this->_links as $link) {
foreach (explode(' ', $link['tags']) as $tag) {
foreach (preg_split('/\s+/', $link['tags'], 0, PREG_SPLIT_NO_EMPTY) as $tag) {
if (empty($tag)) {
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/LinkDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ public function testAllTags()
'-exclude' => 1,
'.hidden' => 1,
'hashtag' => 2,
'tag1' => 1,
'tag2' => 1,
'tag3' => 1,
'tag4' => 1,
),
self::$privateLinkDB->allTags()
);
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/ReferenceLinkDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function __construct()
'',
1,
'20121206_182539',
'dev cartoon'
'dev cartoon tag1 tag2 tag3 tag4 '
);
}

Expand Down

0 comments on commit 58f0660

Please sign in to comment.