You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Trailing dots and spaces in filenames are ignored #9227
This happens regardless of NTS or ZTS builds. The very same happens for trailing spaces. The basic problem is that Windows treats filenames with trailing spaces or dots in a special way, namely that these are basically ignored by most APIs. That article also mentions that leading spaces would be ignored, but I cannot reproduce this (Windows 21H1); maybe that has been changed in the meantime.
Anyhow, the current behavior is very confusing, and doesn't match other systems. Furthermore, there is actually code which is supposed to catch these cases (trailing spaces and dots), and to report ERROR_ACCESS_DENIED:
changed the title [-]Filenames with leading dots or spaces are not properly handled[/-][+]Trailing dots and spaces in filenames are ignored[/+]on Aug 2, 2022
Sorry, first time reporter.
We seem to have found another bug related to this, file_exists() still seems to ignore the trailing dot while realpath() does seem to work correctly.
If we run the file below while the .env file exists
@jasperdevries Thank you for your comment! This looks to be deliberate.
I don't own a Windows machine and didn't try this, but the article linked above indicates that trailing periods are truncated when saving files on Windows.
Correct: as far as I've seen, Windows will drop trailing periods and spaces. Additionally, Explorer apparently drops leading spaces (not periods) when dealing with filenames, but you can get them through other methods.
So if realpath isn't ignoring trailing periods anymore then presumably the other filesystem functions should be updated to match?
It looks like the file_exists function does accept the trailing period but all the other functions don't.
This causes inconsistent behaviour on windows systems, which is visible if you look closely at the test provided by @jasperdevries
Activity
Fix phpGH-9227: Trailing dots and spaces in filenames are ignored
[-]Filenames with leading dots or spaces are not properly handled[/-][+]Trailing dots and spaces in filenames are ignored[/+]jasperdevries commentedon Jun 27, 2023
Sorry, first time reporter.
We seem to have found another bug related to this,
file_exists()still seems to ignore the trailing dot whilerealpath()does seem to work correctly.If we run the file below while the
.envfile existswe get the following results
while we would expect the output to be as followed
We're running this on php 8.2.3 on a windows server.
iluuu1994 commentedon Jun 27, 2023
@jasperdevries Thank you for your comment! This looks to be deliberate.
I don't own a Windows machine and didn't try this, but the article linked above indicates that trailing periods are truncated when saving files on Windows.
https://learn.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/file-folder-name-whitespace-characters
To avoid confusing scenarios like
touch('.env.'); var_dump(file_exists('.env.')); /* false */, other file functions also support (and truncate) trailing periods. See https://github.com/php/php-src/blob/master/ext/standard/tests/file/gh9227.phpt.damianwadley commentedon Jun 27, 2023
Correct: as far as I've seen, Windows will drop trailing periods and spaces. Additionally, Explorer apparently drops leading spaces (not periods) when dealing with filenames, but you can get them through other methods.
So if realpath isn't ignoring trailing periods anymore then presumably the other filesystem functions should be updated to match?
PazkaL commentedon Aug 29, 2023
It looks like the file_exists function does accept the trailing period but all the other functions don't.
This causes inconsistent behaviour on windows systems, which is visible if you look closely at the test provided by @jasperdevries