]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fixes #497: ignore case difference between tags 583/head
authorArthurHoaro <arthur@hoa.ro>
Thu, 14 Apr 2016 15:59:37 +0000 (17:59 +0200)
committerArthurHoaro <arthur@hoa.ro>
Tue, 31 May 2016 07:09:32 +0000 (09:09 +0200)
While retrieving all tags, case differences will be ignored.
This affects:

  * tag cloud
  * tag autocompletion

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

index a62341fc638e2c078e401bdedb58e6aa635e990c..4c1a45b50891c0f865a57760297601396429a065 100644 (file)
@@ -417,11 +417,18 @@ You use the community supported version of the original Shaarli project, by Seba
     public function allTags()
     {
         $tags = array();
+        $caseMapping = array();
         foreach ($this->_links as $link) {
             foreach (explode(' ', $link['tags']) as $tag) {
-                if (!empty($tag)) {
-                    $tags[$tag] = (empty($tags[$tag]) ? 1 : $tags[$tag] + 1);
+                if (empty($tag)) {
+                    continue;
                 }
+                // The first case found will be displayed.
+                if (!isset($caseMapping[strtolower($tag)])) {
+                    $caseMapping[strtolower($tag)] = $tag;
+                    $tags[$caseMapping[strtolower($tag)]] = 0;
+                }
+                $tags[$caseMapping[strtolower($tag)]]++;
             }
         }
         // Sort tags by usage (most used tag first)
index 069b158154f4a3b7eafa516556d2e56bb3d1baec..647b2db24b3619a9afb95e10a7435b6501ae43fb 100644 (file)
@@ -93,7 +93,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
         $this->assertContains('Permalink', $link['description']);
         $this->assertContains('http://host.tld/?WDWyig', $link['description']);
         $this->assertEquals(1, count($link['taglist']));
-        $this->assertEquals('stuff', $link['taglist'][0]);
+        $this->assertEquals('sTuff', $link['taglist'][0]);
 
         // Test URL with external link.
         $this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links']['20150310_114633']['url']);
index 52d31400b5a0716ebce5c2ab51ec3ab008af4c38..8ffb1512db922b33350f4b5be5c3d2a15446fdc1 100644 (file)
@@ -290,7 +290,9 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
                 'stallman' => 1,
                 'free' => 1,
                 '-exclude' => 1,
-                'stuff' => 2,
+                // The DB contains a link with `sTuff` and another one with `stuff` tag.
+                // They need to be grouped with the first case found (`sTuff`).
+                'sTuff' => 2,
             ),
             self::$publicLinkDB->allTags()
         );
@@ -310,7 +312,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
                 'w3c' => 1,
                 'css' => 1,
                 'Mercurial' => 1,
-                'stuff' => 2,
+                'sTuff' => 2,
                 '-exclude' => 1,
                 '.hidden' => 1,
             ),
index dc4f5dfa98ccb7e1fbd28decd67417ca93d46dfa..46165b4d55f36f1ec02f3cb9ad4aa5a68fd6ff99 100644 (file)
@@ -21,7 +21,7 @@ class ReferenceLinkDB
             'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this.',
             0,
             '20150310_114651',
-            'stuff'
+            'sTuff'
         );
 
         $this->addLink(