Avoid substr() error when strpos returns false

"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>
This commit is contained in:
bladewing 2020-07-14 23:10:53 +02:00 committed by backportbot[bot]
parent 48ef5148c1
commit 43e401e3a2
1 changed files with 9 additions and 6 deletions

View File

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