Skip to content

Commit

Permalink
removed custom escape function support from Mojo::Template again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 19, 2012
1 parent 84fea69 commit 6dc78f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
1 change: 0 additions & 1 deletion Changes
@@ -1,6 +1,5 @@

3.49 2012-10-19
- Improved Mojo::Template to allow custom escape functions.
- Improved documentation.
- Improved tests.
- Fixed % escaping bug in Mojo::Parameters. (dmw397)
Expand Down
11 changes: 4 additions & 7 deletions lib/Mojo/Template.pm
Expand Up @@ -93,13 +93,10 @@ sub build {
}
}

# XML escape function (can be redefined)
my $escape
= q/no warnings 'redefine'; sub escape { Mojo::Util::xml_escape($_[0]) }/;

# Escape function with Mojo::ByteStream support
$escape .= q[sub _escape { no warnings 'uninitialized';];
$escape .= q/ref $_[0] eq 'Mojo::ByteStream' ? $_[0] : escape("$_[0]") }/;
# Escape helper
my $escape = q[no warnings 'redefine'; sub _escape {];
$escape .= q/no warnings 'uninitialized'; ref $_[0] eq 'Mojo::ByteStream'/;
$escape .= '? $_[0] : Mojo::Util::xml_escape("$_[0]") }';

# Wrap lines
my $first = $lines[0] ||= '';
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -99,7 +99,7 @@ Perl code, a naive translation could look like this.
$output .= '<ul>';
for my $j (1 .. $i) {
$output .= '<li>';
$output .= escape scalar $j;
$output .= xml_escape scalar $j;
$output .= '</li>';
}
$output .= '</ul>';
Expand Down Expand Up @@ -518,7 +518,7 @@ A naive translation to Perl code could look like this.
my $name = shift;
my $output = '';
$output .= 'Hello ';
$output .= escape scalar $name;
$output .= xml_escape scalar $name;
$output .= '.';
return Mojo::ByteStream->new($output);
}
Expand Down
11 changes: 3 additions & 8 deletions t/mojolicious/twinkle_lite_app.t
@@ -1,7 +1,5 @@
use Mojo::Base -strict;

use utf8;

# Disable IPv6 and libev
BEGIN {
$ENV{MOJO_NO_IPV6} = 1;
Expand All @@ -16,9 +14,6 @@ use Test::Mojo;
# Custom format
app->renderer->default_format('foo');

# Custom escape function
my $escape = 'sub escape { Mojo::Util::html_escape("$_[0]") }';

# Twinkle template syntax
my $twinkle = {
append => '$self->res->headers->header("X-Append" => $prepended);',
Expand All @@ -29,7 +24,7 @@ my $twinkle = {
expression_mark => '*',
line_start => '.',
namespace => 'TwinkleSandBoxTest',
prepend => qq{my \$prepended = \$self->config("foo"); $escape},
prepend => 'my $prepended = $self->config("foo");',
tag_end => '**',
tag_start => '**',
trim_mark => '*'
Expand Down Expand Up @@ -92,7 +87,7 @@ $t->get_ok('/')->status_is(200)->header_is('X-Append' => 'bar')

# GET /advanced
$t->get_ok('/advanced')->status_is(200)->header_is('X-Append' => 'bar')
->content_is("&lt;escape me&gt;&awconint;\n123423");
->content_is("&lt;escape me&gt;\n123423");

# GET /docs
$t->get_ok('/docs')->status_is(200)->content_like(qr!<h3>snowman</h3>!);
Expand Down Expand Up @@ -125,7 +120,7 @@ Hello *** $name **!\
test<%= content %>123\
@@ advanced.foo.twinkle
.** "<escape me>\x{2233}"
.** '<escape me>'
. my $numbers = [1 .. 4];
** for my $i (@$numbers) { ***
*** $i ***
Expand Down

0 comments on commit 6dc78f3

Please sign in to comment.