]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Prevent tag duplicate when renaming 759/head
authorArthurHoaro <arthur@hoa.ro>
Sun, 15 Jan 2017 16:46:24 +0000 (17:46 +0100)
committerArthurHoaro <arthur@hoa.ro>
Sun, 15 Jan 2017 16:46:24 +0000 (17:46 +0100)
Fixes #757

index.php

index beb1cbca592aefae1071254c9ab95c04ea635526..557675629ba38d604efe69aca86b0665f018f856 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1207,15 +1207,15 @@ function renderPage($conf, $pluginManager, $LINKSDB)
             $needle = trim($_POST['fromtag']);
             // True for case-sensitive tag search.
             $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true);
-            foreach($linksToAlter as $key=>$value)
-            {
-                $tags = explode(' ',trim($value['tags']));
-                $tags[array_search($needle,$tags)] = trim($_POST['totag']); // Replace tags value.
-                $value['tags']=trim(implode(' ',$tags));
-                $LINKSDB[$key]=$value;
+            foreach($linksToAlter as $key=>$value) {
+                $tags = preg_split('/\s+/', trim($value['tags']));
+                // Replace tags value.
+                $tags[array_search($needle, $tags)] = trim($_POST['totag']);
+                $value['tags'] = implode(' ', array_unique($tags));
+                $LINKSDB[$key] = $value;
             }
             $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk.
-            echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode($_POST['totag']).'\';</script>';
+            echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>';
             exit;
         }
     }