improve handling of files with special chars

This commit is contained in:
korelstar 2020-11-22 18:12:08 +01:00
parent 330dbcfede
commit d4d75b2e50
2 changed files with 8 additions and 1 deletions

View File

@ -49,8 +49,12 @@ class Note {
throw new \Exception('Can\'t read file content for '.$this->file->getPath());
}
if (!mb_check_encoding($content, 'UTF-8')) {
$this->util->logger->warning(
'File encoding for '.$this->file->getPath().' is not UTF-8. This may cause problems.'
);
$content = mb_convert_encoding($content, 'UTF-8');
}
$content = str_replace([ pack('H*', 'FEFF'), pack('H*', 'FFEF'), pack('H*', 'EFBBBF') ], '', $content);
return $content;
}

View File

@ -94,6 +94,9 @@ class NoteUtil {
$splitContent = preg_split("/\R/u", $content, 2);
$title = trim($splitContent[0]);
// replace (Unicode) white-space with normal space
$title = preg_replace('/\s/u', ' ', $title);
// using a maximum of 100 chars should be enough
$title = mb_substr($title, 0, 100, "UTF-8");
@ -123,7 +126,7 @@ class NoteUtil {
}
// prevent file to be hidden
$str = preg_replace("/^[\. ]+/mu", "", $str);
$str = preg_replace('/^[\.\s]+/mu', '', $str);
return trim($str);
}