Browse Source

Deal with trailing whitespace in media types

microsub
J. King 5 years ago
parent
commit
1809fb254e
  1. 2
      lib/Misc/HTTP.php
  2. 1
      tests/cases/Misc/TestHTTP.php

2
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;
}

1
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],
];
}
}

Loading…
Cancel
Save