Description
Create a file c:\test[x]\test.php (yes, it is important that it is in the directory named test[x]):
<?php
var_dump(glob('*'));
Resulted in this output:
But I expected this output instead:
array(1) {
[0]=>
string(8) "test.php"
}
The problem is that glob performs the expansion of [...] characters in the mask. The mask does not contain these characters, but since it is not absolute, the current directory is added to it:
|
snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern); |
And it contains these characters, so an unwanted expansion occurs. It is therefore necessary to escape these characters. At least the character [ must escaped, ie. replaced with [[] sequence.
PHP Version
PHP 8.3
Operating System
Windows
Description
Create a file
c:\test[x]\test.php(yes, it is important that it is in the directory namedtest[x]):Resulted in this output:
But I expected this output instead:
The problem is that glob performs the expansion of
[...]characters in the mask. The mask does not contain these characters, but since it is not absolute, the current directory is added to it:php-src/ext/standard/dir.c
Line 445 in a651ae8
And it contains these characters, so an unwanted expansion occurs. It is therefore necessary to escape these characters. At least the character
[must escaped, ie. replaced with[[]sequence.PHP Version
PHP 8.3
Operating System
Windows