Ignore:
Timestamp:
Jun 20, 2013, 5:38:47 AM (11 years ago)
Author:
rvelices
Message:

smarty 3 - first pass for tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/smarty/libs/plugins/modifier.regex_replace.php

    r3282 r23384  
    22/**
    33 * Smarty plugin
     4 *
    45 * @package Smarty
    5  * @subpackage plugins
     6 * @subpackage PluginsModifier
    67 */
    7 
    88
    99/**
     
    1313 * Name:     regex_replace<br>
    1414 * Purpose:  regular expression search/replace
     15 *
    1516 * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
    1617 *          regex_replace (Smarty online manual)
    17  * @author   Monte Ohrt <monte at ohrt dot com>
    18  * @param string
    19  * @param string|array
    20  * @param string|array
     18 * @author Monte Ohrt <monte at ohrt dot com>
     19 * @param string       $string   input string
     20 * @param string|array $search   regular expression(s) to search for
     21 * @param string|array $replace  string(s) that should be replaced
    2122 * @return string
    2223 */
     
    2425{
    2526    if(is_array($search)) {
    26       foreach($search as $idx => $s)
    27         $search[$idx] = _smarty_regex_replace_check($s);
     27        foreach($search as $idx => $s) {
     28            $search[$idx] = _smarty_regex_replace_check($s);
     29        }
    2830    } else {
    29       $search = _smarty_regex_replace_check($search);
    30     }       
    31 
     31        $search = _smarty_regex_replace_check($search);
     32    }
    3233    return preg_replace($search, $replace, $string);
    3334}
    3435
     36/**
     37 * @param  string $search string(s) that should be replaced
     38 * @return string
     39 * @ignore
     40 */
    3541function _smarty_regex_replace_check($search)
    3642{
    37     if (($pos = strpos($search,"\0")) !== false)
    38       $search = substr($search,0,$pos);
     43    // null-byte injection detection
     44    // anything behind the first null-byte is ignored
     45    if (($pos = strpos($search,"\0")) !== false) {
     46        $search = substr($search,0,$pos);
     47    }
     48    // remove eval-modifier from $search
    3949    if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
    40         /* remove eval-modifier from $search */
    4150        $search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
    4251    }
     
    4453}
    4554
    46 /* vim: set expandtab: */
    47 
    4855?>
Note: See TracChangeset for help on using the changeset viewer.