]> source.dussan.org Git - nextcloud-server.git/commitdiff
Avoid substr() error when strpos returns false
authorbladewing <lukas@ifflaender-family.de>
Tue, 14 Jul 2020 21:10:53 +0000 (23:10 +0200)
committerlui87kw <lukas.ifflaender@uni-wuerzburg.de>
Wed, 15 Jul 2020 08:18:47 +0000 (10:18 +0200)
"Exception: substr() expects parameter 3 to be int, bool given" can occur on Line 378 $mimePart = substr($icon, 0, strpos($icon, '-'));
This happens, when '-' is not found and strpos returns false instead of an int.
When this occurs, e.g., Activity hangs.

Signed-off-by: lui87kw <lukas.ifflaender@uni-wuerzburg.de>
lib/private/Files/Type/Detection.php

index e882503766663b7809b161b0bbb0dfa18e2cc93f..34caf072d98c393570b1ff60db246629ea910caa 100644 (file)
@@ -373,12 +373,15 @@ class Detection implements IMimeTypeDetector {
                }
 
                // Try only the first part of the filetype
-               $mimePart = substr($icon, 0, strpos($icon, '-'));
-               try {
-                       $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');
-                       return $this->mimetypeIcons[$mimetype];
-               } catch (\RuntimeException $e) {
-                       // Image for the first part of the mimetype not found
+
+               if(strpos($icon, '-')) {
+                       $mimePart = substr($icon, 0, strpos($icon, '-'));
+                       try {
+                               $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');
+                               return $this->mimetypeIcons[$mimetype];
+                       } catch (\RuntimeException $e) {
+                               // Image for the first part of the mimetype not found
+                       }
                }
 
                $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg');