Skip Menu |
 

This queue is for tickets about the HTML-Template CPAN distribution.

Report information
The Basics
Id: 14097
Status: resolved
Priority: 0/
Queue: HTML-Template

People
Owner: Nobody in particular
Requestors: mmitar [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.7
Fixed in: (no value)

Attachments


Subject: ELSE bug
Download (untitled) / with headers
text/plain 357b
For a really simple program: #!/usr/bin/perl -w use strict; use HTML::Template; my $template = HTML::Template->new('filename'=>"test.tmpl"); print $template->output; And this invalid template: Before. <TMPL_IF NAME="TEST"> 1. <TMPL_ELSE> 2. <TMPL_ELSE> 3. </TMPL_IF> After. HTML::Template does not output any error and just simply outputs the 2. case.
From: markstos [...] cpan.org
Download (untitled) / with headers
text/plain 408b
I wrote a test case for this, below. I may see about the code fix after dinner. use Test::More qw/no_plan/; use HTML::Template; eval { my $template = HTML::Template->new( scalarref => \' Before. <TMPL_IF NAME="TEST"> 1. <TMPL_ELSE> 2. <TMPL_ELSE> 3. </TMPL_IF> After.', ); }; isnt($@, '', "including 2 <tmpl_else> tags for one tmpl_if should throw an error");
Subject: PATCH: ELSE bug
From: markstos [...] cpan.org
Download (untitled) / with headers
text/plain 302b
Attached is a complete patch to resolve this. It includes a test case to illustrate it, code to address it, and related MANIFEST and Changes file updates. You may need to apply the patch with an option to ignore whitespace, as i indented a block of the code to make it more readable. Mark
Download else_else.patch
text/x-diff 2.7k
Wed Aug 10 19:43:43 EST 2005 Mark Stosberg <mark@summersault.com> * RT#14097 is fixed. Extra <tmpl_else> tags now die with an error. diff -rN -u old-html-tmpl/Changes new-html-tmpl/Changes --- old-html-tmpl/Changes 2005-08-10 19:45:04.000000000 -0500 +++ new-html-tmpl/Changes 2005-08-10 19:43:26.000000000 -0500 @@ -1,3 +1,7 @@ + - Bug Fix: Including more than one <tmpl_else> tag in <tmpl_unless> or + <tmpl_unless> now dies with an error message, instead of silently ignoring + one of the clauses. (Mitar and Mark Stosberg, RT#14097) + 2.7 Thu Jun 24 12:00:00 2004 - New Feature: Added javascript escaping with ESCAPE=JS. (Craig Manley) diff -rN -u old-html-tmpl/MANIFEST new-html-tmpl/MANIFEST --- old-html-tmpl/MANIFEST 2005-08-10 19:45:04.000000000 -0500 +++ new-html-tmpl/MANIFEST 2005-08-10 19:40:25.000000000 -0500 @@ -3,6 +3,7 @@ Makefile.PL Template.pm t/99-old-test-pl.t +t/else_else_bug.t templates/simple.tmpl templates/simple-loop.tmpl templates/medium.tmpl diff -rN -u old-html-tmpl/Template.pm new-html-tmpl/Template.pm --- old-html-tmpl/Template.pm 2005-08-10 19:45:04.000000000 -0500 +++ new-html-tmpl/Template.pm 2005-08-10 19:37:46.000000000 -0500 @@ -910,6 +910,7 @@ sub WHICH () { 4 }; sub WHICH_IF () { 0 }; sub WHICH_UNLESS () { 1 }; +sub IS_ELSE () { 5 }; # back to the main package scope. package HTML::Template; @@ -2180,10 +2181,12 @@ my $cond = pop(@ifstack); die "HTML::Template->new() : found <TMPL_ELSE> with no matching <TMPL_IF> or <TMPL_UNLESS> at $fname : line $fcounter." unless defined $cond; + die "HTML::Template->new() : found second <TMPL_ELSE> tag for <TMPL_IF> or <TMPL_UNLESS> at $fname : line $fcounter." if $cond->[HTML::Template::COND::IS_ELSE]; my $else = HTML::Template::COND->new($cond->[HTML::Template::COND::VARIABLE]); $else->[HTML::Template::COND::WHICH] = $cond->[HTML::Template::COND::WHICH]; $else->[HTML::Template::COND::JUMP_IF_TRUE] = not $cond->[HTML::Template::COND::JUMP_IF_TRUE]; + $else->[HTML::Template::COND::IS_ELSE] = 1; # need end-block resolution? if (defined($cond->[HTML::Template::COND::VARIABLE_TYPE])) { diff -rN -u old-html-tmpl/t/else_else_bug.t new-html-tmpl/t/else_else_bug.t --- old-html-tmpl/t/else_else_bug.t 1969-12-31 19:00:00.000000000 -0500 +++ new-html-tmpl/t/else_else_bug.t 2005-08-10 19:38:14.000000000 -0500 @@ -0,0 +1,12 @@ + +use Test::More qw/no_plan/; +use HTML::Template; + +eval { + my $template = HTML::Template->new( + debug => 0, + scalarref => \' + Before. <TMPL_IF NAME="TEST"> 1. <TMPL_ELSE> 2. <TMPL_ELSE> 3. </TMPL_IF> After.', + ); +}; +isnt($@, '', "including 2 <tmpl_else> tags for one tmpl_if should throw an error");
Fixed for 2.8.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.