mirror of
https://github.com/php/php-src.git
synced 2026-04-17 13:01:02 +02:00
The `encoding` attribute of the XML declaration is optional; it is good practice to use external encoding information where available if it is missing. Thus, we check for `charset` info of `Content-Type` headers, and see whether the encoding is supported. We cater to trailing parameters and quoted-strings, but not to escaped backslashes and quotes in quoted-strings, since no known character encoding contains these anyway. Co-authored-by: Michael Wallner <mike@php.net> Closes GH-6747.
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
--TEST--
|
|
Bug #51903 (simplexml_load_file() doesn't use HTTP headers)
|
|
--SKIPIF--
|
|
<?php
|
|
if (!extension_loaded('simplexml')) die('skip simplexml extension not available');
|
|
if (@!include "./ext/standard/tests/http/server.inc") die('skip server.inc not available');
|
|
http_server_skipif('tcp://127.0.0.1:12342');
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
require "./ext/standard/tests/http/server.inc";
|
|
$responses = [
|
|
"data://text/plain,HTTP/1.1 200 OK\r\n"
|
|
. "Content-Type: text/xml; charset=ISO-8859-1\r\n\r\n"
|
|
. "<?xml version=\"1.0\"?>\n"
|
|
. "<root>\xE4\xF6\xFC</root>\n",
|
|
"data://text/plain,HTTP/1.1 200 OK\r\n"
|
|
. "Content-Type: text/xml; charset=ISO-8859-1; foo=bar\r\n\r\n"
|
|
. "<?xml version=\"1.0\"?>\n"
|
|
. "<root>\xE4\xF6\xFC</root>\n",
|
|
"data://text/plain,HTTP/1.1 200 OK\r\n"
|
|
. "Content-Type: text/xml; charset=\"ISO-8859-1\" ; foo=bar\r\n\r\n"
|
|
. "<?xml version=\"1.0\"?>\n"
|
|
. "<root>\xE4\xF6\xFC</root>\n",
|
|
];
|
|
$pid = http_server('tcp://127.0.0.1:12342', $responses);
|
|
|
|
for ($i = 0; $i < count($responses); $i++) {
|
|
$sxe = simplexml_load_file('http://127.0.0.1:12342/');
|
|
echo "$sxe\n";
|
|
}
|
|
|
|
http_server_kill($pid);
|
|
?>
|
|
--EXPECT--
|
|
äöü
|
|
äöü
|
|
äöü
|