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

Merge branch 'PHP-8.1'

* PHP-8.1:
  Add FPM test for php_admin_value doc_root usage
  Fix for bug in file handling refactor.
This commit is contained in:
Nikita Popov
2021-11-23 18:36:45 +01:00
3 changed files with 55 additions and 9 deletions

View File

@@ -402,7 +402,7 @@ PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
IS_ABSOLUTE_PATH(PG(doc_root), length)) {
size_t path_len = strlen(path_info);
filename = zend_string_alloc(length + path_len + 2, 0);
memcpy(filename, PG(doc_root), length);
memcpy(ZSTR_VAL(filename), PG(doc_root), length);
if (!IS_SLASH(ZSTR_VAL(filename)[length - 1])) { /* length is never 0 */
ZSTR_VAL(filename)[length++] = PHP_DIR_SEPARATOR;
}

View File

@@ -0,0 +1,46 @@
--TEST--
FPM: php_admin_value doc_root usage
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php
require_once "tester.inc";
$docRoot = __DIR__ . '/';
$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_admin_value[doc_root] = $docRoot
EOT;
$code = <<<EOT
<?php
echo "OK";
EOT;
$tester = new FPM\Tester($cfg, $code);
$sourceFile = $tester->makeSourceFile();
$tester->start();
$tester->expectLogStartNotices();
$tester->request(uri: basename($sourceFile), scriptFilename: $sourceFile)->expectBody('OK');
$tester->terminate();
$tester->close();
?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>

View File

@@ -527,16 +527,14 @@ class Tester
* @param string $query
* @param array $headers
* @param string|null $uri
* @param string|null $address
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $connKeepAlive
* @param string|null $scriptFilename
* @return array
*/
private function getRequestParams(
string $query = '',
array $headers = [],
string $uri = null
string $uri = null,
string $scriptFilename = null
) {
if (is_null($uri)) {
$uri = $this->makeSourceFile();
@@ -546,7 +544,7 @@ class Tester
[
'GATEWAY_INTERFACE' => 'FastCGI/1.0',
'REQUEST_METHOD' => 'GET',
'SCRIPT_FILENAME' => $uri,
'SCRIPT_FILENAME' => $scriptFilename ?: $uri,
'SCRIPT_NAME' => $uri,
'QUERY_STRING' => $query,
'REQUEST_URI' => $uri . ($query ? '?'.$query : ""),
@@ -580,6 +578,7 @@ class Tester
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $connKeepAlive
* @param string|null $scriptFilename = null
* @return Response
*/
public function request(
@@ -589,13 +588,14 @@ class Tester
string $address = null,
string $successMessage = null,
string $errorMessage = null,
bool $connKeepAlive = false
bool $connKeepAlive = false,
string $scriptFilename = null
) {
if ($this->hasError()) {
return new Response(null, true);
}
$params = $this->getRequestParams($query, $headers, $uri);
$params = $this->getRequestParams($query, $headers, $uri, $scriptFilename);
try {
$this->response = new Response(