php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42501 glob() with GLOB_BRACE using Windows paths
Submitted: 2007-08-31 18:05 UTC Modified: 2008-11-10 01:00 UTC
Votes:3
Avg. Score:4.0 ± 0.8
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: eric at ericmmartin dot com Assigned: pajoye (profile)
Status: No Feedback Package: Filesystem function related
PHP Version: 5.2.4 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eric at ericmmartin dot com
New email:
PHP Version: OS:

 

 [2007-08-31 18:05 UTC] eric at ericmmartin dot com
Description:
------------
glob() with the GLOB_BRACE flag seems to have a bug. I believe that the colon (:) in a pattern in braces, is causing the problem.

I tried escaping the colon, but that did not seem to work.



Reproduce code:
---------------
<?php

$paths = '{c:/globtest/firstfolder,c:/globtest/secondfolder}';
$ext = '*.png';
print_r(get_files($paths,$ext));

$paths = 'c:/globtest/';
$ext = '{firstfolder/*.png,secondfolder/*.png}';
print_r(get_files($paths,$ext));

function get_files($paths, $ext) {
    return glob($paths.$ext,GLOB_BRACE);
}

?>

Expected result:
----------------
Array
(
    [0] => c:/globtest/firstfolder/arrow_down.png
    [1] => c:/globtest/firstfolder/arrow_off.png
    [2] => c:/globtest/firstfolder/arrow_up.png
    [3] => c:/globtest/secondfolder/arrow_down.png
    [4] => c:/globtest/secondfolder/arrow_off.png
    [5] => c:/globtest/secondfolder/arrow_up.png
)
Array
(
    [0] => c:/globtest/firstfolder/arrow_down.png
    [1] => c:/globtest/firstfolder/arrow_off.png
    [2] => c:/globtest/firstfolder/arrow_up.png
    [3] => c:/globtest/secondfolder/arrow_down.png
    [4] => c:/globtest/secondfolder/arrow_off.png
    [5] => c:/globtest/secondfolder/arrow_up.png
)

Actual result:
--------------
Array
(
)
Array
(
    [0] => c:/globtest/firstfolder/arrow_down.png
    [1] => c:/globtest/firstfolder/arrow_off.png
    [2] => c:/globtest/firstfolder/arrow_up.png
    [3] => c:/globtest/secondfolder/arrow_down.png
    [4] => c:/globtest/secondfolder/arrow_off.png
    [5] => c:/globtest/secondfolder/arrow_up.png
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-03 11:30 UTC] jani@php.net
Try passing GLOB_NOCHECK as flag too, it should return the actual pattern used then when it doesn't find any files.
 [2007-09-03 14:37 UTC] eric at ericmmartin dot com
I added BLOG_NOCHECK and found that I needed to update my first test (it was missing a directory seperator...but even after fixing that, it still fails. Here are the updated tests and results.

Reproduce code:
---------------
<?php

$paths = '{c:/globtest/firstfolder/,c:/globtest/secondfolder/}';
$ext = '*.png';
print_r(get_files($paths,$ext));

$paths = 'c:/globtest/';
$ext = '{firstfolder/*.png,secondfolder/*.png}';
print_r(get_files($paths,$ext));

function get_files($paths, $ext) {
    return glob($paths.$ext,GLOB_BRACE+GLOB_NOCHECK);
}

?>

Actual result:
--------------
Array
(
    [0] => c:/globtest/firstfolder/*.png
    [1] => c:/globtest/secondfolder/*.png
)
Array
(
    [0] => c:/globtest/firstfolder/arrow_down.png
    [1] => c:/globtest/firstfolder/arrow_off.png
    [2] => c:/globtest/firstfolder/arrow_up.png
    [3] => c:/globtest/secondfolder/arrow_down.png
    [4] => c:/globtest/secondfolder/arrow_off.png
    [5] => c:/globtest/secondfolder/arrow_up.png
)

The pattern looks correct! Even if I use 'arrow_off.png' instead of '*.png' for $ext, glob() fails. It seems like the colon breaks it, for some reason...
 [2007-09-03 14:39 UTC] eric at ericmmartin dot com
From my previous comment: "I added BLOG_NOCHECK and found"...

- I mean GLOB_NOCHECK, of course =)
 [2007-09-23 09:23 UTC] tzachi at zend dot com
It seems to be a problem with PHP thread-safe. With PHP-NTS that is provided from 5.2.1 and on it seems to work as expected. Apparently the thread-safety version (which is what common in windows) of glob has a problem with pattern that begins with '{'.
 [2007-10-05 14:45 UTC] eric at ericmmartin dot com
I have confirmed that the nts version works as expected.

I still believe that the issue is caused by the colon ':' in the pattern portion of the glob call. For example, the following is still problematic in the non-nts version:

<?php

$paths = 'c{:/globtest/firstfolder/,:/globtest/secondfolder/}';
$ext = '*.png';
print_r(get_files($paths,$ext));

$paths = 'c:/globtest/';
$ext = '{firstfolder/*.png,secondfolder/*.png}';
print_r(get_files($paths,$ext));

function get_files($paths, $ext) {
    return glob($paths.$ext,GLOB_BRACE);
}

?>

Notice, I moved the drive letter out of the pattern, so the pattern does not start with a '{'. It works as expected in the nts version.
 [2008-11-02 12:59 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-11-10 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 26 07:01:30 2024 UTC