Bug fix: CleanURL and iconv issue

This commit is contained in:
Diego Najar 2017-10-31 00:06:06 +01:00
parent ebcb7a5b1f
commit a73e0bb86d
2 changed files with 15 additions and 3 deletions

View File

@ -230,6 +230,11 @@ class dbPages extends dbJSON
public function delete($key) 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 // Page doesn't exist in database
if (!$this->exists($key)) { if (!$this->exists($key)) {
Log::set(__METHOD__.LOG_SEP.'The page does not exist. Key: '.$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); $newKey = Text::cleanUrl($parent).'/'.Text::cleanUrl($text);
} }
// cleanURL can return empty string
if (Text::isEmpty($newKey)) {
$newKey = 'empty';
}
if ($newKey!==$oldKey) { if ($newKey!==$oldKey) {
// Verify if the key is already been used // Verify if the key is already been used
if( isset($this->db[$newKey]) ) { if( isset($this->db[$newKey]) ) {

View File

@ -134,7 +134,9 @@ class Text {
$string = str_replace(array_keys(self::$specialChars), self::$specialChars, $string); $string = str_replace(array_keys(self::$specialChars), self::$specialChars, $string);
if (function_exists('iconv')) { if (function_exists('iconv')) {
$string = iconv(CHARSET, 'ASCII//TRANSLIT', $string); if (@iconv(CHARSET, 'ASCII//TRANSLIT//IGNORE', $string)!==false) {
$string = iconv(CHARSET, 'ASCII//TRANSLIT//IGNORE', $string);
}
} }
$string = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $string); $string = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $string);