[Rt-commit] rt branch, 4.2/simple-template-cf, created. rt-4.2.3-172-g546fc6c

Alex Vandiver alexmv at bestpractical.com
Mon Jul 21 15:04:51 EDT 2014


The branch, 4.2/simple-template-cf has been created
        at  546fc6c2c6c02afd8fad503649a06972403f0447 (commit)

- Log -----------------------------------------------------------------
commit 546fc6c2c6c02afd8fad503649a06972403f0447
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Apr 30 19:17:32 2014 -0400

    Strip non-word characters from CF names for variable names
    
    The existing Simple templates did not address the issue of CF names with
    spaces in them.  This strips non-word characters to establish the
    variable name -- a trasformation which might cause duplication of CF
    names, but this does not notably worsen the situation, as they did not
    already posess any uniqueness guarantees.
    
    Note that this may still lead to unicode variable names, as \w is UTF-8
    aware, allowing for the variable "$TicketCFStraße".
    
    Fixes I#18446.

diff --git a/docs/customizing/templates.pod b/docs/customizing/templates.pod
index d61542d..331534c 100644
--- a/docs/customizing/templates.pod
+++ b/docs/customizing/templates.pod
@@ -129,7 +129,9 @@ use.  Among them:
 
 =item $TicketCF(Name)
 
-For example, C<$TicketCFDepartment>.
+For example, C<$TicketCFDepartment>.  For CFs with more complicated
+names, all non-word characters (anything that is not letters, numbers,
+or underscores) are stripped to determine the appropriate variable name.
 
 =item $TransactionType
 
diff --git a/lib/RT/Template.pm b/lib/RT/Template.pm
index 3831f4f..f0a58c6 100644
--- a/lib/RT/Template.pm
+++ b/lib/RT/Template.pm
@@ -640,7 +640,10 @@ sub _MassageSimpleTemplateArgs {
 
         my $cfs = $ticket->CustomFields;
         while (my $cf = $cfs->Next) {
-            $template_args->{"TicketCF" . $cf->Name} = $ticket->CustomFieldValuesAsString($cf->Name);
+            my $simple = $cf->Name;
+            $simple =~ s/\W//g;
+            $template_args->{"TicketCF" . $simple}
+                = $ticket->CustomFieldValuesAsString($cf->Name);
         }
     }
 
@@ -651,7 +654,10 @@ sub _MassageSimpleTemplateArgs {
 
         my $cfs = $txn->CustomFields;
         while (my $cf = $cfs->Next) {
-            $template_args->{"TransactionCF" . $cf->Name} = $txn->CustomFieldValuesAsString($cf->Name);
+            my $simple = $cf->Name;
+            $simple =~ s/\W//g;
+            $template_args->{"TransactionCF" . $simple}
+                = $txn->CustomFieldValuesAsString($cf->Name);
         }
     }
 }

-----------------------------------------------------------------------


More information about the rt-commit mailing list