From: ArthurHoaro Date: Sun, 15 Jan 2017 16:46:24 +0000 (+0100) Subject: Prevent tag duplicate when renaming X-Git-Tag: v0.9.0~64^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=d6327389fc5cbb659e7f32fb61b2f1d5c86b02ee;p=github%2Fshaarli%2FShaarli.git Prevent tag duplicate when renaming Fixes #757 --- diff --git a/index.php b/index.php index beb1cbca..55767562 100644 --- 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 ''; + echo ''; exit; } }