diff --git a/VERSION b/VERSION index 09e8a76..65d4f31 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2408.181640 +0.2408.181655 diff --git a/src/MediaType.php b/src/MediaType.php index cd5a170..dcff15e 100644 --- a/src/MediaType.php +++ b/src/MediaType.php @@ -1,7 +1,7 @@ getParam('q', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); - if(!is_float($quality) && !is_int($quality)) - return 1; + if(is_string($quality) || is_int($quality)) + $quality = (float)$quality; + if(!is_float($quality)) + return 1.0; - return max(min(round($quality, 2), 1), 0); + return max(min(round($quality, 2), 1.0), 0.0); } /** diff --git a/tests/MediaTypeTest.php b/tests/MediaTypeTest.php new file mode 100644 index 0000000..b6230e4 --- /dev/null +++ b/tests/MediaTypeTest.php @@ -0,0 +1,32 @@ + 1.0, + 'application/xhtml+xml' => 1.0, + 'application/xml;q=0.9' => 0.9, + 'image/webp' => 1.0, + '*/*;q=0.8' => 0.8, + ]; + + foreach($types as $typeStr => $expectQuality) { + $type = MediaType::parse($typeStr); + $this->assertEquals($typeStr, (string)$type); + $this->assertEquals($expectQuality, $type->getQuality()); + } + } +}