[Jifty-commit] r5643 - in Template-Declare: lib/Template/Declare t

Jifty commits jifty-commit at lists.jifty.org
Fri Aug 1 17:02:45 EDT 2008


Author: sartak
Date: Fri Aug  1 17:02:44 2008
New Revision: 5643

Added:
   Template-Declare/t/rt-37622.t
Modified:
   Template-Declare/   (props changed)
   Template-Declare/lib/Template/Declare/Tags.pm

Log:
 r68307 at onn:  sartak | 2008-08-01 17:02:35 -0400
 Clear %ATTRIBUTES before calling the subroutine in smart_tag_wrapper so the first tag doesn't get arbitrary data in it.
 
 Resolves rt.cpan.org #37622. Thanks for reporting it, Theory.


Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/lib/Template/Declare/Tags.pm	Fri Aug  1 17:02:44 2008
@@ -546,11 +546,13 @@
 
     Template::Declare->new_buffer_frame;
 
+    my %attr = %ATTRIBUTES;
+    %ATTRIBUTES = ();                              # prevent leakage
+
     my $last = join '',    #
         map { ref($_) ? $_ : _postprocess($_) }    #
-        $coderef->(%ATTRIBUTES);
+        $coderef->(%attr);
 
-    %ATTRIBUTES = ();                              # prevent leakage
 
     if ( length( Template::Declare->buffer->data ) ) {
 
@@ -754,7 +756,6 @@
     $template = _resolve_relative_template_path($template);
     push @TEMPLATE_STACK, $template;
 
-
     my $callable =
         ( ref($template) && $template->isa('Template::Declare::Tag') )
         ? $template

Added: Template-Declare/t/rt-37622.t
==============================================================================
--- (empty file)
+++ Template-Declare/t/rt-37622.t	Fri Aug  1 17:02:44 2008
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+package MyTemplates;
+use strict;
+use warnings;
+use Template::Declare::Tags;
+use base 'Template::Declare';
+
+sub wrap (&) {
+    my $code = shift;
+
+    smart_tag_wrapper {
+        my %p = @_;
+        html {
+            head {
+                title { $p{title} }
+            };
+
+            $code->();
+
+            div {
+                outs 'footer';
+            }
+        }
+    }
+}
+
+template 'test' => sub {
+    with(title => 'Test'),
+    wrap {
+        h1 { "Hello, world!" }
+    };
+};
+
+package main;
+use Test::More tests => 2;
+
+Template::Declare->init(roots => ['MyTemplates']);
+my $output = Template::Declare->show('test');
+
+unlike($output, qr{<html.*title="Test">});
+like($output, qr{<title>\s*Test\s*</title>});
+


More information about the Jifty-commit mailing list