]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #759 from ArthurHoaro/hotfix/dup-tags
authorArthurHoaro <arthur@hoa.ro>
Mon, 16 Jan 2017 11:39:01 +0000 (12:39 +0100)
committerGitHub <noreply@github.com>
Mon, 16 Jan 2017 11:39:01 +0000 (12:39 +0100)
Prevent tag duplicate when renaming

1  2 
index.php

diff --combined index.php
index 32f5ca3c6fb4fe779b0c90cf74bd9106ab7b6dd0,557675629ba38d604efe69aca86b0665f018f856..8055a7b7bde78bfe06f290ce58ec0a647313ab57
+++ b/index.php
@@@ -13,7 -13,7 +13,7 @@@
   *
   * Licence: http://www.opensource.org/licenses/zlib-license.php
   *
 - * Requires: PHP 5.3.x
 + * Requires: PHP 5.5.x
   */
  
  // Set 'UTC' as the default timezone if it is not defined in php.ini
@@@ -83,7 -83,7 +83,7 @@@ use \Shaarli\ThemeUtils
  
  // Ensure the PHP version is supported
  try {
 -    ApplicationUtils::checkPHPVersion('5.3', PHP_VERSION);
 +    ApplicationUtils::checkPHPVersion('5.5', PHP_VERSION);
  } catch(Exception $exc) {
      header('Content-Type: text/plain; charset=utf-8');
      echo $exc->getMessage();
@@@ -1207,15 -1207,15 +1207,15 @@@ function renderPage($conf, $pluginManag
              $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;
          }
      }