diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-06-09 09:59:56 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-06-09 09:59:56 +0300 |
commit | 5e925250938ecf2716d786ed4811d2c49a8cb061 (patch) | |
tree | c9b8dabc1891d9b5a0bb9097981d74770bd75ecd /lib | |
parent | e050c15c23ff624304c41aa8b327b95bf30afb30 (diff) |
An empty string is a valid encoded result
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Service/ApiService.php | 2 | ||||
-rw-r--r-- | lib/Service/EncodingService.php | 3 | ||||
-rw-r--r-- | lib/TextFile.php | 2 |
3 files changed, 4 insertions, 3 deletions
diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 5ed1b3e79..651b1eefc 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -111,7 +111,7 @@ class ApiService { $content = $baseFile->getContent(); $content = $this->encodingService->encodeToUtf8($content); - if (!$content) { + if ($content === null) { $this->logger->log(ILogger::WARN, 'Failed to encode file to UTF8. File ID: ' . $file->getId()); } } catch (NotFoundException $e) { diff --git a/lib/Service/EncodingService.php b/lib/Service/EncodingService.php index 3f5bada06..5026cd9a3 100644 --- a/lib/Service/EncodingService.php +++ b/lib/Service/EncodingService.php @@ -42,7 +42,8 @@ class EncodingService { return null; } - return mb_convert_encoding($string, 'UTF-8', $encoding); + $encoded = mb_convert_encoding($string, 'UTF-8', $encoding); + return is_string($encoded) ? $encoded : null; } public function detectEncoding(string $string): ?string { diff --git a/lib/TextFile.php b/lib/TextFile.php index 30b58c84c..9d632dcfe 100644 --- a/lib/TextFile.php +++ b/lib/TextFile.php @@ -63,7 +63,7 @@ class TextFile implements ISimpleFile { public function getContent() { $content = $this->encodingService->encodeToUtf8($this->file->getContent()); - if (!$content) { + if ($content === null) { throw new NotFoundException('File not compatible with text because it could not be encoded to UTF-8.'); } |