Browse Source

make mime type validation case insensitive for capitalized mime type. closes #13075

Andrej Griniuk 6 years ago
parent
commit
85c6c05764

+ 1 - 1
src/Validation/Validation.php

@@ -1186,7 +1186,7 @@ class Validation
             $mimeTypes[$key] = strtolower($val);
         }
 
-        return in_array($mime, $mimeTypes);
+        return in_array(strtolower($mime), $mimeTypes);
     }
 
     /**

+ 1 - 0
tests/Fixture/sample.algol68

@@ -0,0 +1 @@
+PROC

+ 20 - 0
tests/TestCase/Validation/ValidationTest.php

@@ -2538,6 +2538,26 @@ class ValidationTest extends TestCase
     }
 
     /**
+     * testMimeTypeCaseInsensitive method
+     *
+     * @return void
+     */
+    public function testMimeTypeCaseInsensitive()
+    {
+        $algol68 = CORE_TESTS . 'Fixture/sample.algol68';
+        $File = new File($algol68, false);
+
+        $this->skipIf(!$File->mime(), 'Cannot determine mimeType');
+
+        $this->assertTrue('text/x-Algol68', $File->mime());
+        $this->assertTrue(Validation::mimeType($algol68, ['text/x-Algol68']));
+        $this->assertTrue(Validation::mimeType($algol68, ['text/x-algol68']));
+        $this->assertTrue(Validation::mimeType($algol68, ['text/X-ALGOL68']));
+
+        $this->assertFalse(Validation::mimeType($algol68, ['image/png']));
+    }
+
+    /**
      * Test mimetype with a PSR7 object
      *
      * @return void