From a73e0bb86d144e7e7710f5707fa37f3d389d4609 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Tue, 31 Oct 2017 00:06:06 +0100 Subject: [PATCH] Bug fix: CleanURL and iconv issue --- bl-kernel/dbpages.class.php | 10 ++++++++++ bl-kernel/helpers/text.class.php | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bl-kernel/dbpages.class.php b/bl-kernel/dbpages.class.php index 942f4910..1b0af9d0 100644 --- a/bl-kernel/dbpages.class.php +++ b/bl-kernel/dbpages.class.php @@ -230,6 +230,11 @@ class dbPages extends dbJSON public function delete($key) { + // This is need it, because if the key is empty the Filesystem::deleteRecursive is going to delete PATH_PAGES + if (empty($key)) { + return false; + } + // Page doesn't exist in database if (!$this->exists($key)) { Log::set(__METHOD__.LOG_SEP.'The page does not exist. Key: '.$key); @@ -509,6 +514,11 @@ class dbPages extends dbJSON $newKey = Text::cleanUrl($parent).'/'.Text::cleanUrl($text); } + // cleanURL can return empty string + if (Text::isEmpty($newKey)) { + $newKey = 'empty'; + } + if ($newKey!==$oldKey) { // Verify if the key is already been used if( isset($this->db[$newKey]) ) { diff --git a/bl-kernel/helpers/text.class.php b/bl-kernel/helpers/text.class.php index 87f9b20b..58f0e36d 100644 --- a/bl-kernel/helpers/text.class.php +++ b/bl-kernel/helpers/text.class.php @@ -125,7 +125,7 @@ class Text { public static function cleanUrl($string, $separator='-') { - if(EXTREME_FRIENDLY_URL) { + if (EXTREME_FRIENDLY_URL) { $string = preg_replace("/[\/_|+ -]+/", $separator, $string); return $string; } @@ -133,8 +133,10 @@ class Text { // Transliterate characters to ASCII $string = str_replace(array_keys(self::$specialChars), self::$specialChars, $string); - if(function_exists('iconv')) { - $string = iconv(CHARSET, 'ASCII//TRANSLIT', $string); + if (function_exists('iconv')) { + if (@iconv(CHARSET, 'ASCII//TRANSLIT//IGNORE', $string)!==false) { + $string = iconv(CHARSET, 'ASCII//TRANSLIT//IGNORE', $string); + } } $string = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $string);