Skip to content

Commit

Permalink
Merge pull request #2 from odyniec/master
Browse files Browse the repository at this point in the history
Correctly handle filter arguments with empty values (with tests, hooray!)
  • Loading branch information
sanko committed May 20, 2014
2 parents 2d72415 + c7c4464 commit 91e2f44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Template/Liquid/Variable.pm
Expand Up @@ -33,8 +33,10 @@ sub render {
my %_filters = $s->{template}->filters;
FILTER: for my $filter (@{$s->{filters}}) {
my ($name, $args) = @$filter;
map { $_ = $s->{template}{context}->get($_) || $_ }
@$args;
map {
my $arg_val = $s->{template}{context}->get($_);
$_ = $arg_val if defined $arg_val;
} @$args;
my $package = $_filters{$name};
my $call = $package ? $package->can($name) : ();
if ($call) {
Expand Down
13 changes: 13 additions & 0 deletions t/0100_filters/0101_standard_filters.t
Expand Up @@ -200,6 +200,19 @@ is( Template::Liquid->parse(q[{{ 'bar' | prepend:'foo' }}])->render(),
q[ {{ 'bar' | prepend:'foo' }} => 'foobar']
);

is( Template::Liquid->parse(q[{{ 'bar' | prepend:baz }}])->render(baz => 'foo'),
'foobar',
q[ {{ 'bar' | prepend:baz }} => 'foobar']
);
is( Template::Liquid->parse(q[{{ 'bar' | prepend:baz }}])->render(baz => ''),
'bar',
q[ {{ 'bar' | prepend:baz }} => 'bar']
);
is( Template::Liquid->parse(q[{{ 'bar' | prepend:baz }}])->render(xxx => ''),
'bazbar',
q[ {{ 'bar' | prepend:baz }} => 'bazbar']
);

=head2 C<truncate>
Truncate a string down to C<x> characters.
Expand Down

0 comments on commit 91e2f44

Please sign in to comment.