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:
2
NEWS
2
NEWS
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
33
ext/spl/tests/SplFileInfo_getExtension_basic-win32.phpt
Normal file
33
ext/spl/tests/SplFileInfo_getExtension_basic-win32.phpt
Normal 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) ""
|
||||
@@ -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');
|
||||
|
||||
20
ext/standard/tests/file/gh9227.phpt
Normal file
20
ext/standard/tests/file/gh9227.phpt
Normal 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)
|
||||
Reference in New Issue
Block a user