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)
{
// 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]) ) {

View File

@ -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);