1--TEST--
2DOM\HTMLDocument::createFromFile() HTTP header Content-Type
3--EXTENSIONS--
4dom
5--SKIPIF--
6<?php
7if (@!include "./ext/standard/tests/http/server.inc") die('skip server.inc not available');
8http_server_skipif();
9?>
10--FILE--
11<?php
12require "./ext/standard/tests/http/server.inc";
13
14$tests = [
15    "No slashes" => [
16        "foo",
17        "      ",
18    ],
19    "Invalid type/subtype" => [
20        "/html; Charset=\"ISO-8859-1\"",
21        "text/; Charset=\"ISO-8859-1\"",
22        "tex°t/html; Charset=\"ISO-8859-1\"",
23        "/; Charset=\"ISO-8859-1\"",
24        "$/€; Charset=\"ISO-8859-1\"",
25        "; Charset=\"ISO-8859-1\"",
26        ";",
27        "",
28        "    \t",
29    ],
30    "Valid type/subtype without charset" => [
31        "text/html; x=ISO-8859-1",
32        "text/html; x=\"ISO-8859-1\"",
33        "text/html; charet=\"ISO-8859-1\"",
34        "text/html; chars et=\"ISO-8859-1\"",
35    ],
36    "All valid inputs" => [
37        "text/html; charset=ISO-8859-1",
38        "\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 ",
41        "text/html; foo=bar;charset=ISO-8859-1",
42        "text/html; foo=bar;charset=ISO-8859-1;bar=\"foooooo\"",
43        "text/html;;;; charset=ISO-8859-1",
44        "text/html; Charset=\"ISO-8859-1\"",
45        "text/html; Charset=\"ISO\\-8859-1\"",
46        "text/html; ;;   ; ;; Charset=\"ISO-8859-1\"",
47        "text/html;Charset=\"ISO-8859-1",
48        "tex.t/h#\$%!&'*%2B-.^_`|~tml;Charset=\"ISO-8859-1\"", // Note: have to encode + as 2B because of implementation details of http_server()
49    ],
50    "Valid input, but invalid encoding name" => [
51        "text/html;Charset=\"ISO-8859-1\\",
52        "text/html;Charset=\"ISO-8859-1\\\"",
53        "text/html;Charset=\"foobar\\\"",
54        "text/html;Charset=\"%7F\\\"",
55        "text/html;Charset=\"\\\"",
56        "text/html;Charset=",
57    ],
58];
59
60foreach ($tests as $name => $headers) {
61    echo "--- $name ---\n";
62    $responses = array_map(fn ($header) => "data://text/plain,HTTP/1.1 200 OK\r\nContent-Type: " . $header . "\r\n\r\n" . "<p>\xE4\xF6\xFC</p>\n", $headers);
63    ['pid' => $pid, 'uri' => $uri] = http_server($responses);
64    for ($i = 0; $i < count($responses); $i++) {
65        $result = DOM\HTMLDocument::createFromFile($uri, LIBXML_NOERROR);
66        echo $result->getElementsByTagName("p")[0]->textContent, "\n";
67    }
68    http_server_kill($pid);
69}
70?>
71--EXPECT--
72--- No slashes ---
73���
74���
75--- Invalid type/subtype ---
76���
77���
78���
79���
80���
81���
82���
83���
84���
85--- Valid type/subtype without charset ---
86���
87���
88���
89���
90--- All valid inputs ---
91äöü
92äöü
93äöü
94äöü
95äöü
96äöü
97äöü
98äöü
99äöü
100äöü
101äöü
102äöü
103--- Valid input, but invalid encoding name ---
104���
105���
106���
107���
108���
109���
110