Verified Commit bc5e491c authored by Dave Long's avatar Dave Long
Browse files

Issue #3487488 by kim.pepper, mondrake, dakwamine, smustgrave:...

Issue #3487488 by kim.pepper, mondrake, dakwamine, smustgrave: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) in the extension parts like foo.0.zip

(cherry picked from commit 393baa76)
parent 458241cf
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -915,7 +915,9 @@ public function guessMimeType($path): ?string {
    // then iterate over the file parts, trying to find a match.
    // For 'my.awesome.image.jpeg', we try: 'awesome.image.jpeg', then
    // 'image.jpeg', then 'jpeg'.
    while (array_shift($file_parts)) {
    // We explicitly check for NULL because that indicates that the array is
    // empty.
    while (array_shift($file_parts) !== NULL) {
      $extension = strtolower(implode('.', $file_parts));
      if (isset($this->mapping['extensions'][$extension])) {
        return $this->mapping['mimetypes'][$this->mapping['extensions'][$extension]];
+2 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ public function testFileMimeTypeDetection(): void {
      'foobar.z' => 'application/x-compress',
      'foobar.tar' => 'application/x-tar',
      'foobar.tar.z' => 'application/x-tarz',
      'foobar.0.zip' => 'application/zip',
      'foobar..zip' => 'application/zip',
    ];

    $guesser = $this->container->get('file.mime_type.guesser');