Permalink
Browse files

Merge pull request #9 from eserte/replace-warnings

cease warnings in replace vmethod
  • Loading branch information...
abw committed Apr 19, 2012
2 parents fde062c + 3fe5f0d commit 8d97c6d101035b4d0228de42f4bf011927ac0671
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/Template/VMethods.pm
  2. +7 −1 t/vmethods/replace.t
View
@@ -220,7 +220,7 @@ sub text_replace {
my ($chunk, $start, $end) = @_;
$chunk =~ s{ \\(\\|\$) | \$ (\d+) }{
$1 ? $1
- : ($2 > $#$start || $2 == 0) ? ''
+ : ($2 > $#$start || $2 == 0 || !defined $start->[$2]) ? ''
: substr($text, $start->[$2], $end->[$2] - $start->[$2]);
}exg;
$chunk;
View
@@ -200,4 +200,10 @@ oo\$1 bar
-- expect --
f!! ba!r! f!!ba!r!
-
+-- test --
+-- name: no warnings --
+[% text = 'foo';
+ text.replace('(optional)?(foo)', '$1$2');
+%]
+-- expect --
+foo

0 comments on commit 8d97c6d

Please sign in to comment.