File: HTMLDocument_createFromFile_http_header.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (109 lines) | stat: -rw-r--r-- 2,941 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
--TEST--
Dom\HTMLDocument::createFromFile() HTTP header Content-Type
--EXTENSIONS--
dom
--SKIPIF--
<?php
if (@!include "./ext/standard/tests/http/server.inc") die('skip server.inc not available');
http_server_skipif();
?>
--FILE--
<?php
require "./ext/standard/tests/http/server.inc";

$tests = [
    "No slashes" => [
        "foo",
        "      ",
    ],
    "Invalid type/subtype" => [
        "/html; Charset=\"ISO-8859-1\"",
        "text/; Charset=\"ISO-8859-1\"",
        "tex°t/html; Charset=\"ISO-8859-1\"",
        "/; Charset=\"ISO-8859-1\"",
        "$/€; Charset=\"ISO-8859-1\"",
        "; Charset=\"ISO-8859-1\"",
        ";",
        "",
        "    \t",
    ],
    "Valid type/subtype without charset" => [
        "text/html; x=ISO-8859-1",
        "text/html; x=\"ISO-8859-1\"",
        "text/html; charet=\"ISO-8859-1\"",
        "text/html; chars et=\"ISO-8859-1\"",
    ],
    "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",
        "text/html; Charset=\"ISO-8859-1\"",
        "text/html; Charset=\"ISO\\-8859-1\"",
        "text/html; ;;   ; ;; Charset=\"ISO-8859-1\"",
        "text/html;Charset=\"ISO-8859-1",
        "tex.t/h#\$%!&'*%2B-.^_`|~tml;Charset=\"ISO-8859-1\"", // Note: have to encode + as 2B because of implementation details of http_server()
    ],
    "Valid input, but invalid encoding name" => [
        "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=",
    ],
];

foreach ($tests as $name => $headers) {
    echo "--- $name ---\n";
    $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);
    ['pid' => $pid, 'uri' => $uri] = http_server($responses);
    for ($i = 0; $i < count($responses); $i++) {
        $result = Dom\HTMLDocument::createFromFile($uri, LIBXML_NOERROR);
        echo $result->getElementsByTagName("p")[0]->textContent, "\n";
    }
    http_server_kill($pid);
}
?>
--EXPECT--
--- No slashes ---
���
���
--- Invalid type/subtype ---
���
���
���
���
���
���
���
���
���
--- Valid type/subtype without charset ---
���
���
���
���
--- All valid inputs ---
äöü
äöü
äöü
äöü
äöü
äöü
äöü
äöü
äöü
äöü
äöü
äöü
--- Valid input, but invalid encoding name ---
���
���
���
���
���
���