1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

More testing of mime_sniff and fix off-by-one causing trailing whitespace to not be always stripped (#12935)

This commit is contained in:
Niels Dossche
2023-12-12 16:44:36 +00:00
committed by GitHub
parent e78966386b
commit 34ec4b3568
2 changed files with 14 additions and 1 deletions

View File

@@ -12,6 +12,10 @@ http_server_skipif();
require "./ext/standard/tests/http/server.inc";
$tests = [
"No slashes" => [
"foo",
" ",
],
"Invalid type/subtype" => [
"/html; Charset=\"ISO-8859-1\"",
"text/; Charset=\"ISO-8859-1\"",
@@ -32,6 +36,8 @@ $tests = [
"All valid inputs" => [
"text/html; charset=ISO-8859-1",
"\t\r text/html; charset=ISO-8859-1 \t",
"\t\r text/html; charset=ISO-8859-1 \t;bar=\"foo\"",
"\t\r text/html; charset=ISO-8859-1 \t;bar=\"foo\"\r\n\t ",
"text/html; foo=bar;charset=ISO-8859-1",
"text/html; foo=bar;charset=ISO-8859-1;bar=\"foooooo\"",
"text/html;;;; charset=ISO-8859-1",
@@ -45,6 +51,7 @@ $tests = [
"text/html;Charset=\"ISO-8859-1\\",
"text/html;Charset=\"ISO-8859-1\\\"",
"text/html;Charset=\"foobar\\\"",
"text/html;Charset=\"%7F\\\"",
"text/html;Charset=\"\\\"",
"text/html;Charset=",
],
@@ -62,6 +69,9 @@ foreach ($tests as $name => $headers) {
}
?>
--EXPECT--
--- No slashes ---
<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>
--- Invalid type/subtype ---
<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>
@@ -88,9 +98,12 @@ foreach ($tests as $name => $headers) {
äöü
äöü
äöü
äöü
äöü
--- Valid input, but invalid encoding name ---
<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD>

View File

@@ -195,7 +195,7 @@ PHP_LIBXML_API zend_string *php_libxml_sniff_charset_from_string(const char *sta
while (start < end && is_http_whitespace(*start)) {
start++;
}
while (start < end && is_http_whitespace(*end)) {
while (start < end && is_http_whitespace(*(end - 1))) {
end--;
}