Show
Ignore:
Timestamp:
2008-07-23 14:29:20 (6 months ago)
Author:
fredck
Message:

Fixed #1422 : Multiple variables declared in a single "var" statement are now properly renamed by the compressor.
This fix impacted also in the renaming of nested functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • FCKpackager/trunk/_source/includes/fckfunctionprocessor.inc

    r2078 r2268  
    5757                        $processed = $this->_ProcessVars( $processed, $this->_Parameters ) ; 
    5858 
    59                 $numVarMatches = preg_match_all( '/\bvar\b\s+([\w_][\w\d_]+)/', $processed, $varsMatches ) ; 
     59                // Match "var" declarations. 
     60                $numVarMatches = preg_match_all( '/\bvar\b\s+((?:({(?:(?>[^{}]*)|(?2))*})|[^;])+?)(?=(?:\bin\b)|;)/', $processed, $varsMatches ) ; 
    6061 
    6162                if ( $numVarMatches > 0 ) 
     
    6566                        for ( $i = 0 ; $i < $numVarMatches ; $i++ ) 
    6667                        { 
    67                                 $vars[] = $varsMatches[1][$i] ; 
     68                                $varsMatch = $varsMatches[1][$i]; 
     69                                 
     70                                // Removed all (...), [...] and {...} blocks from the var 
     71                                // statement to avoid problems with commas inside them. 
     72                                $varsMatch = preg_replace( '/(\((?:(?>[^\(\)]*)|(?1))*\))+/', '', $varsMatch ) ; 
     73                                $varsMatch = preg_replace( '/(\[(?:(?>[^\[\]]*)|(?1))*\])+/', '', $varsMatch ) ; 
     74                                $varsMatch = preg_replace( '/({(?:(?>[^{}]*)|(?1))*})+/', '', $varsMatch ) ; 
     75                                 
     76                                $numVarNameMatches = preg_match_all( '/(?:^|,)\s*([^\s=,]+)/', $varsMatch, $varNameMatches ) ; 
     77                                 
     78                                for ( $j = 0 ; $j < $numVarNameMatches ; $j++ ) 
     79                                { 
     80                                        $vars[] = $varNameMatches[1][$j] ; 
     81                                } 
    6882                        } 
    6983 
     
    7993                { 
    8094                        if ( strlen( $var) > 1 ) 
    81                                 $source = preg_replace( '/(?<!\w|\d|\.)' . $var . '(?!\w|\d)/', $this->_GetVarName(), $source ) ; 
     95                                $source = preg_replace( '/(?<!\w|\d|\.)' . preg_quote( $var ) . '(?!\w|\d)/', $this->_GetVarName(), $source ) ; 
    8296                } 
    8397 
     
    95109                $var = $this->_VarPrefix . $this->_VarChars[ $this->_LastCharIndex++ ] ; 
    96110 
    97                 if ( preg_match( '/(?<!\w|\d|\.)' . $var . '(?!\w|\d)/', $this->_Function ) ) 
     111                if ( preg_match( '/(?<!\w|\d|\.)' . preg_quote( $var ) . '(?!\w|\d)/', $this->_Function ) ) 
    98112                        return $this->_GetVarName() ; 
    99113                else