Skip to content

Commit

Permalink
fixed Mojo::Template expressions and escaped expressions to consisten…
Browse files Browse the repository at this point in the history
…tly enforce scalar context
  • Loading branch information
kraih committed Feb 18, 2012
1 parent d8d1fe4 commit 3ad201c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 47 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 Mojo::Template expressions and escaped expressions to
consistently enforce scalar context.
- Fixed small bugs in makefile command. (tempire, marcus, sri)

2.49 2012-02-13 00:00:00
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Template.pm
Expand Up @@ -94,11 +94,11 @@ sub build {
my $a = $self->auto_escape;
if (($type eq 'escp' && !$a) || ($type eq 'expr' && $a)) {
$lines[-1] .= "\$_M .= escape";
$lines[-1] .= " +$value" if length $value;
$lines[-1] .= " scalar $value" if length $value;
}

# Raw
else { $lines[-1] .= "\$_M .= $value" }
else { $lines[-1] .= "\$_M .= scalar $value" }
}

# Multiline
Expand Down
55 changes: 10 additions & 45 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 => 197;

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

# Consistent scalar context
my $mt = Mojo::Template->new;
my $output =
$mt->render('<%= localtime 784111777 %>:<%== localtime 784111777 %>');
is $output, "Sun Nov 6 09:49:37 1994:Sun Nov 6 09:49:37 1994\n",
'same context';

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

# Trim expression
Expand Down Expand Up @@ -263,48 +270,6 @@ $output = $mt->render(<<'EOF');
EOF
is $output, "<html>\n\n", 'escaped expression block';

# Captured escaped expression block (passed through with extra whitespace)
$mt = Mojo::Template->new;
$output = $mt->render(<<'EOF');
<%== my $result = capture begin =%>
<html>
<% end =%>
<%= $result =%>
EOF
is $output, "<html>\n<html>\n", 'captured escaped expression block';

# Captured escaped expression block
# (passed through with perl lines and extra whitespace)
$mt = Mojo::Template->new;
$output = $mt->render(<<'EOF');
%== my $result = capture begin
<html>
% end
<%= $result =%>
EOF
is $output, <<EOF, 'captured escaped expression block';
<html>
<html>
EOF

# Captured escaped expression block
# (passed through with indented perl lines and extra whitespace)
$mt = Mojo::Template->new;
$output = $mt->render(<<'EOF');
%== my $result = capture begin
<html>
% end
<%= $result =%>
EOF
is $output, <<EOF, 'captured escaped expression block';
<html>
<html>
EOF

# Capture lines (passed through with extra whitespace)
$mt = Mojo::Template->new;
$output = $mt->render(<<'EOF');
Expand Down

0 comments on commit 3ad201c

Please sign in to comment.