improve handling of files with special chars
This commit is contained in:
parent
330dbcfede
commit
d4d75b2e50
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue