[Rt-commit] rt branch, 4.2/improve-subject-parsing, updated. rt-4.0.0rc7-249-g99bc8f5

Shawn Moore sartak at bestpractical.com
Tue Apr 26 15:13:49 EDT 2011


The branch, 4.2/improve-subject-parsing has been updated
       via  99bc8f5693e5840ec7ced3272b229b6db8b69d82 (commit)
      from  c942cf92df4d309b5a21a1b69df61a91b0e55d19 (commit)

Summary of changes:
 etc/RT_Config.pm.in       |    9 +--------
 lib/RT/Interface/Email.pm |   10 ++++++----
 2 files changed, 7 insertions(+), 12 deletions(-)

- Log -----------------------------------------------------------------
commit 99bc8f5693e5840ec7ced3272b229b6db8b69d82
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Apr 26 15:00:29 2011 -0400

    Assign capture groups and pull out the last as $id
    
        This works around admins using (...) instead of (?:...) and
        destroying their subject tag parsing.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 2fa417d..f947b20 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -289,14 +289,7 @@ you're not dealing with historical C<$rtname> values, you'll likely
 never have to change this configuration.
 
 Be B<very careful> with it. Note that it overrides C<$rtname> for
-subject token matching and that you should use only "non-capturing"
-parenthesis grouping. For example:
-
-C<Set($EmailSubjectTagRegex, qr/(?:example.com|example.org)/i );>
-
-and NOT
-
-C<Set($EmailSubjectTagRegex, qr/(example.com|example.org)/i );>
+subject token matching.
 
 The setting below would make RT behave exactly as it does without the
 setting enabled.
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 6b74460..55f97ef 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -1190,13 +1190,15 @@ sub ParseTicketId {
     my $rtname = RT->Config->Get('rtname');
     my $test_name = RT->Config->Get('EmailSubjectTagRegex') || qr/\Q$rtname\E/i;
 
+    # We use @captures and pull out the last capture value to guard against
+    # someone using (...) instead of (?:...) in $EmailSubjectTagRegex.
     my $id;
-    if ( $Subject =~ /\[$test_name\s+\#(\d+)\s*\]/i ) {
-        $id = $1;
+    if ( my @captures = $Subject =~ /\[$test_name\s+\#(\d+)\s*\]/i ) {
+        $id = $captures[-1];
     } else {
         foreach my $tag ( RT->System->SubjectTag ) {
-            next unless $Subject =~ /\[\Q$tag\E\s+\#(\d+)\s*\]/i;
-            $id = $1;
+            next unless my @captures = $Subject =~ /\[\Q$tag\E\s+\#(\d+)\s*\]/i;
+            $id = $captures[-1];
             last;
         }
     }

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


More information about the Rt-commit mailing list