From 1809fb254e7cadb43ca6319fa656a9de8ff26d93 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 27 Sep 2019 22:54:33 -0400 Subject: [PATCH] Deal with trailing whitespace in media types --- lib/Misc/HTTP.php | 2 +- tests/cases/Misc/TestHTTP.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Misc/HTTP.php b/lib/Misc/HTTP.php index 78a817b..15bfce9 100644 --- a/lib/Misc/HTTP.php +++ b/lib/Misc/HTTP.php @@ -12,7 +12,7 @@ class HTTP { public static function matchType(MessageInterface $msg, string ...$type): bool { $header = $msg->getHeaderLine("Content-Type") ?? ""; foreach ($type as $t) { - $pattern = "/^".preg_quote(trim($t), "/")."($|;|,)/i"; + $pattern = "/^".preg_quote(trim($t), "/")."\s*($|;|,)/i"; if (preg_match($pattern, $header)) { return true; } diff --git a/tests/cases/Misc/TestHTTP.php b/tests/cases/Misc/TestHTTP.php index 5d6f465..70d1316 100644 --- a/tests/cases/Misc/TestHTTP.php +++ b/tests/cases/Misc/TestHTTP.php @@ -27,6 +27,7 @@ class TestHTTP extends \JKingWeb\Arsse\Test\AbstractTest { ["text/json; charset=utf-8", ["application/json", "text/json"], true], ["", ["application/json"], false], ["", ["application/json", ""], true], + ["application/json ;", ["application/json"], true], ]; } }