]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Better whitespace handling in tags 618/head
authorArthurHoaro <arthur@hoa.ro>
Tue, 2 Aug 2016 08:34:21 +0000 (10:34 +0200)
committerArthurHoaro <arthur@hoa.ro>
Tue, 2 Aug 2016 08:34:21 +0000 (10:34 +0200)
Correct PR #573 to work properly with hidden tags, and add ReferenceLinkDB UT.

Fixes #571 - Closes #573

application/LinkDB.php
tests/LinkDBTest.php
tests/utils/ReferenceLinkDB.php

index e9d216ea649dcb7c16354616c8849038ddc7889d..d80434bfe9afcadebc5005d3c825ebef0d6c4add 100644 (file)
@@ -291,7 +291,7 @@ You use the community supported version of the original Shaarli project, by Seba
 
             // Remove private tags if the user is not logged in.
             if (! $this->_loggedIn) {
-                $link['tags'] = preg_replace('/(^|\s*)\.[^($| )]+\s*$/', '', $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 '?').
index e413928afa2bdddb5ef7b78c86059c9fb2f83615..31306069853b1b31820aa1c7388755e5293ee85f 100644 (file)
@@ -317,6 +317,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
                 '-exclude' => 1,
                 '.hidden' => 1,
                 'hashtag' => 2,
+                'tag1' => 1,
+                'tag2' => 1,
+                'tag3' => 1,
+                'tag4' => 1,
             ),
             self::$privateLinkDB->allTags()
         );
@@ -429,30 +433,4 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
     {
         self::$publicLinkDB->filterHash('');
     }
-
-    /**
-     * test whitespace handling in tags.
-     * split on whitespace runs and don't allow empty tags.
-     */
-    public function testReadTagsWithWhitespace()
-    {
-        // test load contains "tags": " tag1  tag2   tag3  tag4   "
-        $ds  = '<?php /* ';
-        $ds .= 'fY5BDoMwDAS/gvwB4hRKMY9BEaASNQKUuL1U/L22D721Odheez';
-        $ds .= 'baQEjvQtgSeIdX12I/onfyYAjU6e1GkOL2mAMvMPxAC8mWIydD';
-        $ds .= 'enHsU0jrXlj1heCZk5k7gpX5oLr+ErUdkGBeypTjwXHfdOUItD';
-        $ds .= 'XycbgXHb24KxFYafWVtYvVRoQiQhw5vixrJDdY/LyENP5PcJ4f */ ?>';
-        file_put_contents(self::$testDatastore, $ds);
-        self::$publicLinkDB = new LinkDB(self::$testDatastore, false, false);
-
-        $this->assertEquals(
-            array(
-                'tag1' => 1,
-                'tag2' => 1,
-                'tag3' => 1,
-                'tag4' => 1
-            ),
-            self::$publicLinkDB->allTags()
-        );
-    }
 }
index fe16baac2e20788f2cb5c491e37ea8ad97cf4e9a..fcc7a4f9f753ba3c4463fa798c0877932132a642 100644 (file)
@@ -75,7 +75,7 @@ class ReferenceLinkDB
             '',
             1,
             '20121206_182539',
-            'dev cartoon'
+            'dev cartoon tag1  tag2   tag3  tag4   '
         );
     }