Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed inconsistency between expressions and escaped expressions in Mo…
…jo::Template
  • Loading branch information
kraih committed Feb 17, 2012
1 parent 3c7b999 commit f2782f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -11,6 +11,8 @@ This file documents the revision history for Perl extension Mojolicious.
Mojo::Message.
- Improved resilience of Mojo::IOLoop::Client.
- Improved documentation.
- Fixed inconsistency between expressions and escaped expressions in
Mojo::Template.
- Fixed small bugs in makefile command. (tempire, marcus, sri)

2.49 2012-02-13 00:00:00
Expand Down
11 changes: 4 additions & 7 deletions lib/Mojo/Template.pm
Expand Up @@ -38,13 +38,10 @@ sub capture;
*capture = sub { shift->(@_) };
sub escape;
*escape = sub {
return "$_[0]" if ref $_[0] && ref $_[0] eq 'Mojo::ByteStream';
my $v;
{
no warnings 'uninitialized';
$v = "$_[0]";
}
Mojo::Util::xml_escape $v;
return scalar @_ if @_ > 1;
return $_[0] if ref $_[0] && ref $_[0] eq 'Mojo::ByteStream';
no warnings 'uninitialized';
Mojo::Util::xml_escape "$_[0]";
};
use Mojo::Base -strict;
EOF
Expand Down
11 changes: 8 additions & 3 deletions t/mojo/template.t
Expand Up @@ -17,7 +17,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 199;
use Test::More tests => 200;

use File::Spec::Functions qw/catfile splitdir/;
use File::Temp;
Expand All @@ -27,9 +27,14 @@ use FindBin;
# like God must feel when he's holding a gun."
use_ok 'Mojo::Template';

# Trim tag
# Consistent scalar context
my $mt = Mojo::Template->new;
my $output = $mt->render(" ♥ <%= 'test♥' =%> \n");
my $output = $mt->render('<%= @{[qw/a b c/]} %>:<%== @{[qw/a b c/]} %>');
is $output, "3:3\n", 'same context';

# Trim tag
$mt = Mojo::Template->new;
$output = $mt->render(" ♥ <%= 'test♥' =%> \n");
is $output, ' ♥test♥', 'tag trimmed';

# Trim expression
Expand Down

0 comments on commit f2782f2

Please sign in to comment.