Changeset 2872

Show
Ignore:
Timestamp:
08/01/08 00:45:44 (4 months ago)
Author:
bchoate
Message:

Fixed indirect variable usage and allow negative values for array index. BugId:80893, 80900

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-42/lib/MT/Template/ContextHandlers.pm

    r2869 r2872  
    25482548 
    25492549    my $start = (exists $args->{from} ? $args->{from} : $args->{start}) || 0; 
    2550     $start = 0 unless $start =~ /^\d+$/; 
     2550    $start = 0 unless $start =~ /^-?\d+$/; 
    25512551    my $end = (exists $args->{to} ? $args->{to} : $args->{end}) || 0; 
    2552     return q() unless $end =~ /^\d+$/; 
     2552    return q() unless $end =~ /^-?\d+$/; 
    25532553    my $incr = $args->{increment} || $args->{step} || 1; 
     2554    # FIXME: support negative "step" values 
    25542555    $incr = 1 unless $incr =~ /^\d+$/; 
     2556    $incr = 1 unless $incr; 
    25552557 
    25562558    my $builder = $ctx->stash('builder'); 
     
    33623364    } 
    33633365 
    3364     if ($name =~ m/^$/) { 
     3366    if ($name =~ m/^\$/) { 
    33653367        $name = $ctx->var($name); 
    33663368    } 
     
    33853387            } elsif (ref($value) eq 'ARRAY') { 
    33863388                if ( defined $index ) { 
    3387                     if ($index =~ /^\d+$/) { 
     3389                    if ($index =~ /^-?\d+$/) { 
    33883390                        $value = $value->[ $index ]; 
    33893391                    } else { 
     
    54925494    my $tag = lc $ctx->stash('tag'); 
    54935495    my $name = $args->{name} || $args->{var}; 
    5494     if ($name =~ m/^$/) { 
     5496    if ($name =~ m/^\$/) { 
    54955497        $name = $ctx->var($name); 
    54965498    } 
     
    56605662    } 
    56615663 
    5662     if ($name =~ m/^$/) { 
     5664    if ($name =~ m/^\$/) { 
    56635665        $name = $ctx->var($name); 
    56645666        return $ctx->error(MT->translate( 
     
    56865688    } 
    56875689    elsif ( 'ARRAY' eq ref($existing) ) { 
    5688         $existing = ( defined $index && ( $index =~ /^\d+$/ ) ) 
     5690        $existing = ( defined $index && ( $index =~ /^-?\d+$/ ) ) 
    56895691          ? $existing->[ $index ]  
    56905692          : undef; 
     
    57195721            unless 'ARRAY' eq ref($data); 
    57205722        return $ctx->error( MT->translate("Invalid index.") ) 
    5721             unless $index =~ /^\d+$/; 
     5723            unless $index =~ /^-?\d+$/; 
    57225724        $data->[ $index ] = $val; 
    57235725    } 
  • branches/release-42/php/lib/block.mtsetvarblock.php

    r1174 r2872  
    4141        } 
    4242 
    43         if (preg_match('/^$/', $name)) { 
     43        if (preg_match('/^\$/', $name)) { 
    4444            $name = $vars[$name]; 
    4545            if (!isset($name)) 
     
    140140    return ''; 
    141141} 
    142 ?> 
  • branches/release-42/php/lib/function.mtsetvar.php

    r2304 r2872  
    5151    } 
    5252 
    53     if (preg_match('/^$/', $name)) { 
     53    if (preg_match('/^\$/', $name)) { 
    5454        $name = $vars[$name]; 
    5555        if (!isset($name)) 
     
    148148    return ''; 
    149149} 
    150 ?>