diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2025-02-05 11:51:10 +0100 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2025-02-05 12:35:41 +0100 |
commit | 6baafd82b65eb8021d9611319886d19c28586e1f (patch) | |
tree | 00f7a5c42bd5bb15d0f4ef7914f884e5ed4dcd5b /lib | |
parent | 83e35b69915039a6c174be6e471145673995e439 (diff) | |
download | nextcloud-server-6baafd82b65eb8021d9611319886d19c28586e1f.tar.gz nextcloud-server-6baafd82b65eb8021d9611319886d19c28586e1f.zip |
fix: make sure we process mime extensions as string
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Type/Detection.php | 15 | ||||
-rw-r--r-- | lib/public/Files/IMimeTypeDetector.php | 6 | ||||
-rw-r--r-- | lib/public/Files/IMimeTypeLoader.php | 10 |
3 files changed, 27 insertions, 4 deletions
diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index b1e4c098e54..e8fbab0330e 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -23,6 +23,7 @@ class Detection implements IMimeTypeDetector { private const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json'; private const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json'; + /** @var array<string, array{string, string|null}> */ protected array $mimetypes = []; protected array $secureMimeTypes = []; @@ -52,6 +53,8 @@ class Detection implements IMimeTypeDetector { public function registerType(string $extension, string $mimetype, ?string $secureMimeType = null): void { + // Make sure the extension is a string + // https://github.com/nextcloud/server/issues/42902 $this->mimetypes[$extension] = [$mimetype, $secureMimeType]; $this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype; } @@ -66,13 +69,17 @@ class Detection implements IMimeTypeDetector { * @param array $types */ public function registerTypeArray(array $types): void { - $this->mimetypes = array_merge($this->mimetypes, $types); + // Register the types, + foreach ($types as $extension => $mimeType) { + $this->registerType((string)$extension, $mimeType[0], $mimeType[1] ?? null); + } // Update the alternative mimetypes to avoid having to look them up each time. foreach ($this->mimetypes as $extension => $mimeType) { - if (str_starts_with($extension, '_comment')) { + if (str_starts_with((string)$extension, '_comment')) { continue; } + $this->secureMimeTypes[$mimeType[0]] = $mimeType[1] ?? $mimeType[0]; if (isset($mimeType[1])) { $this->secureMimeTypes[$mimeType[1]] = $mimeType[1]; @@ -133,7 +140,7 @@ class Detection implements IMimeTypeDetector { } /** - * @return array + * @return array<string, array{string, string|null}> */ public function getAllMappings(): array { $this->loadMappings(); @@ -163,7 +170,7 @@ class Detection implements IMimeTypeDetector { $extension = strrchr($fileName, '.'); if ($extension !== false) { $extension = strtolower($extension); - $extension = substr($extension, 1); //remove leading . + $extension = substr($extension, 1); // remove leading . return $this->mimetypes[$extension][0] ?? 'application/octet-stream'; } } diff --git a/lib/public/Files/IMimeTypeDetector.php b/lib/public/Files/IMimeTypeDetector.php index 1c683cdd4b9..4a5f4635cc1 100644 --- a/lib/public/Files/IMimeTypeDetector.php +++ b/lib/public/Files/IMimeTypeDetector.php @@ -73,4 +73,10 @@ interface IMimeTypeDetector { * @since 28.0.0 */ public function getAllAliases(): array; + + /** + * @return array<string,string> + * @since 8.2.0 + */ + public function getAllMappings(): array; } diff --git a/lib/public/Files/IMimeTypeLoader.php b/lib/public/Files/IMimeTypeLoader.php index 44261527d53..d98c3ab4356 100644 --- a/lib/public/Files/IMimeTypeLoader.php +++ b/lib/public/Files/IMimeTypeLoader.php @@ -47,4 +47,14 @@ interface IMimeTypeLoader { * @since 8.2.0 */ public function reset(): void; + + /** + * Update filecache mimetype based on file extension + * + * @param string $ext + * @param int $mimeTypeId + * @return int + * @since 8.2.0 + */ + public function updateFilecache(string $ext, int $mimeTypeId): int; } |