File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ class Mimeparse
2727 *
2828 * @param string $mimeType
2929 * @return array ($type, $subtype, $params)
30+ * @throws UnexpectedValueException when $mimeType does not include a valid subtype
3031 */
3132 public static function parseMimeType ($ mimeType )
3233 {
@@ -51,7 +52,7 @@ public static function parseMimeType($mimeType)
5152 list ($ type , $ subtype ) = explode ('/ ' , $ fullType );
5253
5354 if (!$ subtype ) {
54- throw ( new \Exception ('malformed mime type ' ) );
55+ throw new \UnexpectedValueException ('malformed mime type ' );
5556 }
5657
5758 return array (trim ($ type ), trim ($ subtype ), $ params );
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ class MimeparseTest extends \PHPUnit_Framework_TestCase
55{
66 /**
77 * @covers Bitworking\Mimeparse::parseMediaRange
8+ * @covers Bitworking\Mimeparse::parseMimeType
89 */
910 public function testParseMediaRange ()
1011 {
@@ -35,6 +36,16 @@ public function testParseMediaRange()
3536 ), Mimeparse::parseMediaRange (' *; q=.2 ' ));
3637 }
3738
39+ /**
40+ * @covers Bitworking\Mimeparse::parseMimeType
41+ * @expectedException UnexpectedValueException
42+ * @expectedExceptionMessage malformed mime type
43+ */
44+ public function testParseMimeTypeWithMalformedMimeType ()
45+ {
46+ $ parsed = Mimeparse::parseMimeType ('application/;q=1 ' );
47+ }
48+
3849 /**
3950 * @covers Bitworking\Mimeparse::quality
4051 */
You can’t perform that action at this time.
0 commit comments