Skip Menu |

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

Report information
The Basics
Id: 24183
Status: resolved
Worked: 5 min
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: BMORROW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 2.15
Fixed in: (no value)



Subject: SWITCH fails when CASE value has regex metachars in
(Sorry, my previous report was incomplete: I submitted it by mistake.) When using SWITCH, if a CASE value has regex metacharacters in it will fail to match as expected. The template below indicates the problem: [% foo = 'a(b)' bar = 'a(b)' %] [% SWITCH foo %] [% CASE bar %] ok [% CASE %] not ok [% END %] The attached patch to lib/Template/Directive.pm fixes the problem. If this is intended behaviour, it should be documented, and a .quotemeta scalar vmethod would be useful, to allow matching literally.
Subject: TT2-SWITCH.patch
--- Directive.pm.orig 2007-01-02 09:29:23.000000000 +0000 +++ Directive.pm 2007-01-02 09:29:58.000000000 +0000 @@ -573,7 +573,7 @@ $caseblock .= <<EOF; \$match = $match; \$match = [ \$match ] unless ref \$match eq 'ARRAY'; -if (grep(/^\$result\$/, \@\$match)) { +if (grep(/^\\Q\$result\\E\$/, \@\$match)) { $block last SWITCH; }
Patch applied, somewhat belatedly. Many thanks. A