Changeset 1586

Show
Ignore:
Timestamp:
04/28/08 12:21:34 (7 months ago)
Author:
moeffju
Message:

Really fix #182 this time. Thanks lildude for the debugging help.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/classes/utils.php

    r1585 r1586  
    734734    public static function glob( $pattern, $flags = 0 ) 
    735735    { 
    736         if ( ! defined( 'GLOB_NOBRACE' ) || ! ( ( $flags & GLOB_BRACE ) == GLOB_BRACE ) ) { 
    737             // this platform supports GLOB_BRACE out of the box 
     736            if ( ! defined( 'GLOB_NOBRACE' ) || ! ( ( $flags & GLOB_BRACE ) == GLOB_BRACE ) ) { 
     737            // this platform supports GLOB_BRACE out of the box or GLOB_BRACE wasn't requested 
    738738            $results= glob( $pattern, $flags ); 
    739739        } 
    740740        elseif ( ! preg_match_all( '/\{.*?\}/', $pattern, $m ) ) { 
    741             // this pattern doesn't even use braces 
     741            // GLOB_BRACE used, but this pattern doesn't even use braces 
    742742            $results= glob( $pattern, $flags ^ GLOB_BRACE ); 
    743743        } 
     
    746746            $braces= array(); 
    747747            foreach ( $m[0] as $raw_brace ) { 
    748                 $braces[ preg_quote( $raw_brace ) ] = '(' . str_replace( ',', '|', preq_quote( substr( $raw_brace, 1, -1 ) ) ) . ')'; 
     748                $braces[ preg_quote( $raw_brace ) ] = '(?:' . str_replace( ',', '|', preg_quote( substr( $raw_brace, 1, -1 ), '/' ) ) . ')'; 
    749749            } 
    750750            $new_pattern= preg_replace( '/\{.*?\}/', '*', $pattern ); 
    751             $regex= '/' . str_replace( array_keys( $braces ), array_values( $braces ), preg_quote( $pattern ) ) . '/'; 
    752             $results= preg_grep( $regex, glob( $new_pattern, $flags ^ GLOB_BRACE) ); 
    753         } 
    754  
     751      $pattern= preg_quote( $pattern, '/' ); 
     752      $pattern= str_replace( '\\*', '.*', $pattern ); 
     753      $pattern= str_replace( '\\?', '.', $pattern ); 
     754            $regex= '/' . str_replace( array_keys( $braces ), array_values( $braces ), $pattern ) . '/'; 
     755            $results= preg_grep( $regex, Utils::glob( $new_pattern, $flags ^ GLOB_BRACE) ); 
     756        } 
     757         
    755758        if ( $results === false ) $results= array(); 
    756759        return $results;