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;
}