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

Fix GH-9227: Trailing dots and spaces in filenames are ignored

Given that Windows ignores trailing dots and spaces in filenames, we
catch that ourselves to avoid confusion with the respective filenames
without these characters.

Closes GH-9229.
This commit is contained in:
Christoph M. Becker
2022-08-16 13:34:14 +02:00
parent 1109989bbd
commit a1f5c8a587
5 changed files with 66 additions and 0 deletions

2
NEWS
View File

@@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug GH-9323 (Crash in ZEND_RETURN/GC/zend_call_function)
(Tim Starling)
. Fixed bug GH-9227 (Trailing dots and spaces in filenames are ignored).
(cmb)
- DOM:
. Fixed bug #79451 (Using DOMDocument->replaceChild on doctype causes

View File

@@ -603,6 +603,7 @@ retry_reparse_point:
if (!pathw) {
return (size_t)-1;
}
PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, (size_t)-1, 1);
hFind = FindFirstFileExW(pathw, FindExInfoBasic, &dataw, FindExSearchNameMatch, NULL, 0);
if (INVALID_HANDLE_VALUE == hFind) {
if (use_realpath == CWD_REALPATH) {
@@ -1139,7 +1140,13 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
if (path_length == (size_t)-1) {
#ifdef ZEND_WIN32
if (errno != EACCES) {
errno = ENOENT;
}
#else
errno = ENOENT;
#endif
return 1;
}

View File

@@ -0,0 +1,33 @@
--TEST--
SPL: SplFileInfo::getExtension() basic test
--SKIPIF--
<?php
if (PHP_OS_FAMILY !== "Windows") die("skip only for Windows");
?>
--FILE--
<?php
$file = md5('SplFileInfo::getExtension');
$exts = array('.txt', '.extension', '..', '');
foreach ($exts as $ext) {
touch($file . $ext);
$info = new SplFileInfo($file . $ext);
var_dump($info->getExtension(), pathinfo($file . $ext, PATHINFO_EXTENSION));
}
?>
--CLEAN--
<?php
$file = md5('SplFileInfo::getExtension');
$exts = array('.txt', '.extension', '..', '');
foreach ($exts as $ext) {
@unlink($file . $ext);
}
?>
--EXPECT--
string(3) "txt"
string(3) "txt"
string(9) "extension"
string(9) "extension"
string(0) ""
string(0) ""
string(0) ""
string(0) ""

View File

@@ -1,5 +1,9 @@
--TEST--
SPL: SplFileInfo::getExtension() basic test
--SKIPIF--
<?php
if (PHP_OS_FAMILY === "Windows") die("skip not for Windows");
?>
--FILE--
<?php
$file = md5('SplFileInfo::getExtension');

View File

@@ -0,0 +1,20 @@
--TEST--
Bug GH-9227 (Trailing dots and spaces in filenames are ignored)
--SKIPIF--
<?php
if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only");
?>
--FILE--
<?php
var_dump(realpath(__DIR__ . "/gh9227.txt."));
var_dump(file_put_contents(__DIR__ . "/gh9227.txt", "bar"));
var_dump(realpath(__DIR__ . "/gh9227.txt."));
?>
--CLEAN--
<?php
@unlink(__DIR__ . "/gh9227.txt");
?>
--EXPECT--
bool(false)
int(3)
bool(false)