Req #77523 [Opn]: extend glob pattern limit of 2048 characters
| From: | cmb@php.net | Date: | Fri, 14 Jun 2019 09:11:50 +0000 |
| Subject: | Req #77523 [Opn]: extend glob pattern limit of 2048 characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221301@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77523&edit=1
ID: 77523
Updated by: cmb@php.net
Reported by: nospam at unclassified dot de
-Summary: extend glob pattern limit of 260 characters
+Summary: extend glob pattern limit of 2048 characters
Status: Open
Type: Feature/Change Request
Package: *Directory/Filesystem functions
Operating System: Windows 10.1709
PHP Version: 7.1.26
Block user comment: N
Private report: N
New Comment:
Like @requinix already stated, the maximum allowed pattern length
is 2048 as of PHP 7.1. I do not see the need to extend this.
Previous Comments:
------------------------------------------------------------------------
[2019-01-26 09:30:54] nospam at unclassified dot de
I need a safe and reliable way to determine the true casing of a file name. On Linux it's easy,
spell it as it is or you won't find it. Windows is more tolerant, accepting anything you throw
at it. But that also means that my pages are accessible through a number of different URLs. I need
my pages to be accessible on exactly one URL, so I'm correcting the spelling to the true file
name. On Linux, this also allows me to accept different casing but redirect the user to the correct
name.
I'm running XAMPP with Apache and PHP on Windows. It uses mod_php. I haven't tested this
on Linux yet, that would be an Ubuntu 16.04 system with its default PHP packages and FastCGI.
------------------------------------------------------------------------
[2019-01-26 00:03:23] requinix@php.net
If you're on Windows then case doesn't matter, and even if it did this feels like an abuse
of glob(). Tokenizing by slash and recursively scandir()ing makes more sense to me.
It's true that PHP's glob() limits the pattern to MAXPATHLEN characters when this
doesn't quite make sense - with features like [] and {} the pattern can certainly be longer
than the filenames it would match. So perhaps that check should be dropped.
Regardless, on my Win 10 PHP 7.1 the (PHP_)MAXPATHLEN is 2048 and your code runs fine. What SAPI
(eg, php-fpm, cli) are you running this from, and did you get PHP from windows.php.net or somewhere
else?
------------------------------------------------------------------------
[2019-01-25 23:24:17] nospam at unclassified dot de
Description:
------------
This is what I do:
glob("pages/[Cc][Oo][Nn][Tt][Aa][Cc][Tt]/[Oo][Dd][Ll][Rr]0[Vv][Ss]8[Cc][Gg][Rr][Jj][Bb][Ii][Ll][Aa][Ww][Gg][Pp][Nn][Bb][Tt][Rr]4[Uu][Dd]3[Bb][Nn][Kk][Aa][Ee]/[Dd][Ee][Mm][Oo]/[Ii][Mm][Gg]/[Vv][Ss]2018[Jj][Aa][Vv][Aa][Ss][Cc][Rr][Ii][Pp][Tt][Ww][Aa][Rr][Nn][Ii][Nn][Gg][Ss].[Pp][Nn][Gg]")
This is what I get:
Warning: glob(): Pattern exceeds the maximum allowed length of 260 characters
The string passed to glob() is 279 characters long. And it may even be longer. I has to be this
complicated to determine the correct casing of a file name on disk.
This restriction is neither documented nor understandable. The pattern length should not matter at
all. And even if you think that file paths of actual files in the filesystem are limited to 260
characters on Windows, you may need to update your knowledge from at least 20 years ago. This
restriction only exists for deprecated legacy software, which I hope PHP is not.
Test script:
---------------
See above.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77523&edit=1