@@ -23,6 +23,7 @@ class Detection implements IMimeTypeDetector {
2323 private const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json ' ;
2424 private const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json ' ;
2525
26+ /** @var array<string, list{string, string|null}> */
2627 protected array $ mimetypes = [];
2728 protected array $ secureMimeTypes = [];
2829
@@ -52,6 +53,8 @@ public function __construct(
5253 public function registerType (string $ extension ,
5354 string $ mimetype ,
5455 ?string $ secureMimeType = null ): void {
56+ // Make sure the extension is a string
57+ // https://github.com/nextcloud/server/issues/42902
5558 $ this ->mimetypes [$ extension ] = [$ mimetype , $ secureMimeType ];
5659 $ this ->secureMimeTypes [$ mimetype ] = $ secureMimeType ?: $ mimetype ;
5760 }
@@ -66,13 +69,17 @@ public function registerType(string $extension,
6669 * @param array $types
6770 */
6871 public function registerTypeArray (array $ types ): void {
69- $ this ->mimetypes = array_merge ($ this ->mimetypes , $ types );
72+ // Register the types,
73+ foreach ($ types as $ extension => $ mimeType ) {
74+ $ this ->registerType ((string )$ extension , $ mimeType [0 ], $ mimeType [1 ] ?? null );
75+ }
7076
7177 // Update the alternative mimetypes to avoid having to look them up each time.
7278 foreach ($ this ->mimetypes as $ extension => $ mimeType ) {
73- if (str_starts_with ($ extension , '_comment ' )) {
79+ if (str_starts_with (( string ) $ extension , '_comment ' )) {
7480 continue ;
7581 }
82+
7683 $ this ->secureMimeTypes [$ mimeType [0 ]] = $ mimeType [1 ] ?? $ mimeType [0 ];
7784 if (isset ($ mimeType [1 ])) {
7885 $ this ->secureMimeTypes [$ mimeType [1 ]] = $ mimeType [1 ];
@@ -133,7 +140,7 @@ private function loadMappings(): void {
133140 }
134141
135142 /**
136- * @return array
143+ * @return array<string, list{string, string|null}>
137144 */
138145 public function getAllMappings (): array {
139146 $ this ->loadMappings ();
@@ -163,7 +170,7 @@ public function detectPath($path): string {
163170 $ extension = strrchr ($ fileName , '. ' );
164171 if ($ extension !== false ) {
165172 $ extension = strtolower ($ extension );
166- $ extension = substr ($ extension , 1 ); //remove leading .
173+ $ extension = substr ($ extension , 1 ); // remove leading .
167174 return $ this ->mimetypes [$ extension ][0 ] ?? 'application/octet-stream ' ;
168175 }
169176 }
0 commit comments