Skip to content

Commit 34ec4b3

Browse files
authored
More testing of mime_sniff and fix off-by-one causing trailing whitespace to not be always stripped (#12935)
1 parent e789663 commit 34ec4b3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ext/dom/tests/modern/html/encoding/HTMLDocument_createFromFile_http_header.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ http_server_skipif();
1212
require "./ext/standard/tests/http/server.inc";
1313

1414
$tests = [
15+
"No slashes" => [
16+
"foo",
17+
" ",
18+
],
1519
"Invalid type/subtype" => [
1620
"/html; Charset=\"ISO-8859-1\"",
1721
"text/; Charset=\"ISO-8859-1\"",
@@ -32,6 +36,8 @@ $tests = [
3236
"All valid inputs" => [
3337
"text/html; charset=ISO-8859-1",
3438
"\t\r text/html; charset=ISO-8859-1 \t",
39+
"\t\r text/html; charset=ISO-8859-1 \t;bar=\"foo\"",
40+
"\t\r text/html; charset=ISO-8859-1 \t;bar=\"foo\"\r\n\t ",
3541
"text/html; foo=bar;charset=ISO-8859-1",
3642
"text/html; foo=bar;charset=ISO-8859-1;bar=\"foooooo\"",
3743
"text/html;;;; charset=ISO-8859-1",
@@ -45,6 +51,7 @@ $tests = [
4551
"text/html;Charset=\"ISO-8859-1\\",
4652
"text/html;Charset=\"ISO-8859-1\\\"",
4753
"text/html;Charset=\"foobar\\\"",
54+
"text/html;Charset=\"%7F\\\"",
4855
"text/html;Charset=\"\\\"",
4956
"text/html;Charset=",
5057
],
@@ -62,6 +69,9 @@ foreach ($tests as $name => $headers) {
6269
}
6370
?>
6471
--EXPECT--
72+
--- No slashes ---
73+
���
74+
���
6575
--- Invalid type/subtype ---
6676
���
6777
���
@@ -88,9 +98,12 @@ foreach ($tests as $name => $headers) {
8898
äöü
8999
äöü
90100
äöü
101+
äöü
102+
äöü
91103
--- Valid input, but invalid encoding name ---
92104
���
93105
���
94106
���
95107
���
96108
���
109+
���

ext/libxml/mime_sniff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ PHP_LIBXML_API zend_string *php_libxml_sniff_charset_from_string(const char *sta
195195
while (start < end && is_http_whitespace(*start)) {
196196
start++;
197197
}
198-
while (start < end && is_http_whitespace(*end)) {
198+
while (start < end && is_http_whitespace(*(end - 1))) {
199199
end--;
200200
}
201201

0 commit comments

Comments
 (0)