Skip to content

Commit

Permalink
fixed bug that prevented helper names from ending with "begin"
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 3, 2012
1 parent 9a525a1 commit 6fcb370
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -6,6 +6,7 @@ This file documents the revision history for Perl extension Mojolicious.
- Improved documentation.
- Improved tests.
- Fixed bug that prevented helper names from starting with "end". (Akron)
- Fixed bug that prevented helper names from ending with "begin".
- Fixed empty frame handling in Mojo::Transaction::WebSocket.

2.92 2012-04-30
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Template.pm
Expand Up @@ -189,17 +189,17 @@ sub parse {
|
\Q$tag\E # Code
|
\Q$cpst\E\s*\Q$trim$end\E # Trim end (start)
(?<!\w)\Q$cpst\E\s*\Q$trim$end\E # Trim end (start)
|
\Q$trim$end\E # Trim end
|
\Q$cpst\E\s*\Q$end\E # End (start)
(?<!\w)\Q$cpst\E\s*\Q$end\E # End (start)
|
\Q$end\E # End
)
/x;
my $cpen_re = qr/^(\Q$tag\E)(?:\Q$expr\E)?(?:\Q$escp\E)?\s*\Q$cpen\E(?!\w)/;
my $end_re = qr/^(?:(\Q$cpst\E)\s*)?(\Q$trim\E)?\Q$end\E$/;
my $end_re = qr/^(?:(?<!\w)(\Q$cpst\E)\s*)?(\Q$trim\E)?\Q$end\E$/;

# Split lines
my $state = 'text';
Expand Down
24 changes: 23 additions & 1 deletion t/mojo/template.t
Expand Up @@ -17,7 +17,7 @@ use Mojo::Base -strict;

use utf8;

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

# "When I held that gun in my hand, I felt a surge of power...
# like God must feel when he's holding a gun."
Expand Down Expand Up @@ -144,6 +144,28 @@ EOF
is $output, "% my \$number = 23;\nThe number is <%= \$number %>.\n",
'mixed lines have been replaced';

# Helper starting with "end"
$mt = Mojo::Template->new(
prepend => 'no warnings "redefine"; sub endpoint { "works!" }');
$output = $mt->render(<<'EOF');
% endpoint;
%= endpoint
%== endpoint
<% endpoint; %><%= endpoint %><%== endpoint %>\
EOF
is $output, "works!\nworks!\nworks!works!", 'helper worked';

# Helper ending with "begin"
$mt = Mojo::Template->new(
prepend => 'no warnings "redefine"; sub funbegin { "works too!" }');
$output = $mt->render(<<'EOF');
% funbegin;
%= funbegin
%== funbegin
<% funbegin; %><%= funbegin %><%== funbegin %>\
EOF
is $output, "works too!\nworks too!\nworks too!works too!", 'helper worked';

# Catched exception
$mt = Mojo::Template->new;
$output = $mt->render(<<'EOF');
Expand Down
18 changes: 1 addition & 17 deletions t/mojolicious/lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 690;
use Test::More tests => 685;

# "Wait you're the only friend I have...
# You really want a robot for a friend?
Expand Down Expand Up @@ -38,7 +38,6 @@ app->defaults(default => 23);
helper test_helper => sub { shift->param(@_) };
helper test_helper2 => sub { shift->app->controller_class };
helper dead => sub { die $_[1] || 'works!' };
helper endpoint => sub {'works!'};
is app->test_helper('foo'), undef, 'no value yet';
is app->test_helper2, 'Mojolicious::Controller', 'right value';

Expand Down Expand Up @@ -392,9 +391,6 @@ get '/app' => {layout => 'app'};
get '/helper' => sub { shift->render(handler => 'ep') } => 'helper';
app->helper(agent => sub { shift->req->headers->user_agent });

# GET /helper/endpoint
get '/helper/endpoint' => 'endpoint';

# GET /eperror
get '/eperror' => sub { shift->render(handler => 'ep') } => 'eperror';

Expand Down Expand Up @@ -1143,12 +1139,6 @@ $t->get_ok('/helper', {'User-Agent' => 'Explorer'})->status_is(200)
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is("23\n<br>\n&lt;...\n/template\n(Explorer)");

# GET /helper/endpoint
$t->get_ok('/helper/endpoint')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_is("works!\nworks!\nworks!works!");

# GET /eperror
$t->get_ok('/eperror')->status_is(500)
->header_is(Server => 'Mojolicious (Perl)')
Expand Down Expand Up @@ -1445,12 +1435,6 @@ app layout <%= content %><%= app->mode %>
%= url_for 'index'
(<%= agent %>)\
@@ endpoint.html.ep
% endpoint;
%= endpoint
%== endpoint
<% endpoint; %><%= endpoint %><%== endpoint %>\
@@ eperror.html.ep
%= $c->foo('bar');
Expand Down

0 comments on commit 6fcb370

Please sign in to comment.