Development

#2482: new_fix_for_req_garble.patch

You must first sign up to be able to contribute.

Ticket #2482: new_fix_for_req_garble.patch

File new_fix_for_req_garble.patch, 5.2 kB (added by manickam, 1 year ago)

New fix for Request garbling ( this fix is for server side), also preserving parameters with empty string as value

  • lib/routing/sfPathInfoRouting.class.php

    old new  
    8181 
    8282    for ($i = 0; $i < $count; $i++) 
    8383    { 
    84       // see if there's a value associated with this parameter, if not we're done with path data 
     84      // see if there's a value associated with this parameter, 
     85      // if not, set the value to empty string 
     86      // But if parameter is empty string, ignore subsequent value 
     87 
    8588      if ($count > ($i + 1)) 
    8689      { 
    87         $this->currentRouteParameters[$array[$i]] = $array[++$i]
     90        ($array[$i] != '') ? ($this->currentRouteParameters[$array[$i]] = $array[++$i]) : ++$i
    8891      } 
     92      else 
     93      { 
     94        ($array[$i] != '') ? ($this->currentRouteParameters[$array[$i]] = '') : ''; 
     95      } 
    8996    } 
    9097 
    9198    return $this->currentRouteParameters; 
  • lib/routing/sfPatternRouting.class.php

    old new  
    491491      $url = substr($url, 0, $pos); 
    492492    } 
    493493 
     494    //To fix multiple slash case causing request_params to get garbled 
     495    $orig_url = $url;  
     496    preg_match_all( '#/+#', $orig_url, $slashes );  
     497 
    494498    // we remove multiple / 
    495499    $url = preg_replace('#/+#', '/', $url); 
    496500    $out = array(); 
     
    504508 
    505509      $break = false; 
    506510 
    507       if (preg_match($regexp, $url, $r)) 
     511      if (preg_match($regexp, $url, $r, PREG_OFFSET_CAPTURE)) 
    508512      { 
    509513        $break = true; 
    510514 
     
    531535        } 
    532536 
    533537        $pos = 0; 
    534         foreach ($r as $found
     538        foreach ($r as $founded
    535539        { 
     540      $found = $founded[0]; 
     541 
    536542          // if $found is a named url element (i.e. ':action') 
    537543          if (isset($names[$pos])) 
    538544          { 
     
    541547          // unnamed elements go in as 'pass' 
    542548          else 
    543549          { 
     550            //To fix multiple slashes case causing request params to get garbled 
     551            $prev_slash_count = substr_count( substr( $url, 0, $founded[1] ), '/' ); 
     552            $in_slash_count = substr_count( substr( $url, $founded[1], strlen( $found ) ), '/' ); 
     553 
     554            $prev_offset = $end_offset = 0; 
     555            for( $i=0; $i<$prev_slash_count; $i++ ) 
     556            { 
     557              $prev_offset += strlen( $slashes[0][$i] ) -1; 
     558            } 
     559 
     560            for( ; $i<$prev_slash_count + $in_slash_count; $i++) 
     561            { 
     562              $end_offset += strlen( $slashes[0][$i] ) -1; 
     563            } 
     564 
     565            $found = substr( $orig_url, $prev_offset + $founded[1], strlen($found) + $end_offset ); 
     566            //End of "To fix multiple slashes case causing request params to get garbled" 
     567 
    544568            $pass = explode('/', $found); 
    545569            $found = ''; 
    546570            for ($i = 0, $max = count($pass); $i < $max; $i += 2) 
    547571            { 
    548               if (!isset($pass[$i + 1])) 
    549               { 
    550                 continue; 
    551               } 
     572              if ($pass[$i] == '') continue;//If key is empty, ignore subsequent value.. Instead If value alone is absent, set key to empty string. 
    552573 
    553574              $found .= $pass[$i].'='.$pass[$i + 1].'&'; 
    554575            } 
  • lib/util/sfSimpleAutoload.class.php

    old new  
    141141    require_once(dirname(__FILE__).'/sfFinder.class.php'); 
    142142 
    143143    $finder = sfFinder::type('file')->ignore_version_control()->follow_link()->name('*'.$ext); 
    144     foreach (glob($dir) as $dir) 
     144 
     145    if (($dirs = glob($dir))) 
    145146    { 
    146       if (in_array($dir, $this->dirs)
     147      foreach (glob($dir) as $dir
    147148      { 
    148         if ($this->cacheLoaded
     149        if (in_array($dir, $this->dirs)
    149150        { 
    150           continue; 
     151          if ($this->cacheLoaded) 
     152          { 
     153            continue; 
     154          } 
    151155        } 
     156        else 
     157        { 
     158          $this->dirs[] = $dir; 
     159        } 
     160   
     161        $this->cacheChanged = true; 
     162        $this->addFiles($finder->in($dir), false); 
    152163      } 
    153       else 
    154       { 
    155         $this->dirs[] = $dir; 
    156       } 
    157  
    158       $this->cacheChanged = true; 
    159       $this->addFiles($finder->in($dir), false); 
    160164    } 
    161165  } 
    162166