[Rt-commit] rt branch, 4.0/loc-escape-squares, updated. rt-4.0.4-155-g3754c0a

Thomas Sibley trs at bestpractical.com
Tue Mar 20 16:35:47 EDT 2012


The branch, 4.0/loc-escape-squares has been updated
       via  3754c0ac4eaa97cecad534964d7952829ae3a490 (commit)
       via  969dfcc589f4854e04f8a3b1545db5d7e4a09908 (commit)
       via  23a2160ddc2dbd053327c131469725ba15dd30b9 (commit)
      from  40efce541e1ce822b23b647c21a13a6def20bb92 (commit)

Summary of changes:
 lib/RT/SavedSearch.pm          |   22 ++++++++++++++++++++++
 share/html/Elements/ShowSearch |   10 +---------
 share/html/Prefs/Search.html   |    2 +-
 t/web/custom_frontpage.t       |   21 ++++++++++++++++++++-
 4 files changed, 44 insertions(+), 11 deletions(-)

- Log -----------------------------------------------------------------
commit 23a2160ddc2dbd053327c131469725ba15dd30b9
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Mar 20 15:49:48 2012 -0400

    Failing tests for square brackets in a system saved search

diff --git a/t/web/custom_frontpage.t b/t/web/custom_frontpage.t
index 43c5f6e..5a29eb8 100644
--- a/t/web/custom_frontpage.t
+++ b/t/web/custom_frontpage.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 use strict;
 
-use RT::Test tests => 12;
+use RT::Test tests => 19;
 my ($baseurl, $m) = RT::Test->started_ok;
 
 my $url = $m->rt_base_url;
@@ -88,3 +88,22 @@ $m->click_button( name => 'add' );
 $m->get($url);
 $m->content_like( qr/special chars \[test\] \d+ \[_1\]/,
     'special chars in titlebox' );
+
+
+# Edit a system saved search to contain "[more]"
+{
+    my $search = RT::Attribute->new( RT->SystemUser );
+    $search->LoadByNameAndObject( Name => 'Search - My Tickets', Object => RT->System );
+    my ($id, $desc) = ($search->id, RT->SystemUser->loc($search->Description, '"N"'));
+    ok $id, 'loaded search attribute';
+
+    $m->get_ok($url);
+    $m->follow_link_ok({ url_regex => qr"Prefs/Search\.html\?name=.+?Attribute-$id" }, 'Edit link');
+    $m->content_contains($desc, "found description: $desc");
+
+    ok +($search->SetDescription( $search->Description . " [more]" ));
+
+    $m->get_ok($m->uri); # "reload_ok"
+    $m->content_contains($desc . " [more]", "found description: $desc");
+}
+

commit 969dfcc589f4854e04f8a3b1545db5d7e4a09908
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Mar 20 16:04:12 2012 -0400

    Refactor loc-safe escaping of saved search descriptions

diff --git a/lib/RT/SavedSearch.pm b/lib/RT/SavedSearch.pm
index 8eae317..f09fc83 100644
--- a/lib/RT/SavedSearch.pm
+++ b/lib/RT/SavedSearch.pm
@@ -115,6 +115,28 @@ sub UpdateAttribute {
     return ($status, $msg);
 }
 
+=head2 RT::SavedSearch->EscapeDescription STRING
+
+This is a class method because system-level saved searches aren't true
+C<RT::SavedSearch> objects but direct C<RT::Attribute> objects.
+
+Returns C<STRING> with all square brackets except those in C<[_1]> escaped,
+ready for passing as the first argument to C<loc()>.
+
+=cut
+
+sub EscapeDescription {
+    my $self = shift;
+    my $desc = shift;
+    if ($desc) {
+        # We only use [_1] in saved search descriptions, so let's escape other "["
+        # and "]" unless they are escaped already.
+        $desc =~ s/(?<!~)\[(?!_1\])/~[/g;
+        $desc =~ s/(?<!~)(?<!\[_1)\]/~]/g;
+    }
+    return $desc;
+}
+
 =head2 Type
 
 Returns the type of this search, e.g. 'Ticket'.  Useful for denoting the
diff --git a/share/html/Elements/ShowSearch b/share/html/Elements/ShowSearch
index 8ee267f..cc6e6b8 100644
--- a/share/html/Elements/ShowSearch
+++ b/share/html/Elements/ShowSearch
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <&|/Widgets/TitleBox,
-    title => loc($desc, $ProcessedSearchArg->{'Rows'}),
+    title => loc(RT::SavedSearch->EscapeDescription($search->Description), $ProcessedSearchArg->{'Rows'}),
     title_href => $query_link_url.$QueryString,
     titleright => $customize ? loc('Edit') : '',
     titleright_href => $customize,
@@ -141,14 +141,6 @@ foreach ( $SearchArg, $ProcessedSearchArg ) {
 }
 
 my $QueryString = '?' . $m->comp( '/Elements/QueryString', %$SearchArg );
-
-my $desc = $search->Description;
-
-# we only use [_1] here, let's escape other "[" and "]" unless they are
-# escaped already
-$desc =~ s/(?<!~)\[(?!_1\])/~[/g;
-$desc =~ s/(?<!~)(?<!\[_1)\]/~]/g;
-
 </%init>
 <%ARGS>
 $Name           => undef

commit 3754c0ac4eaa97cecad534964d7952829ae3a490
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Mar 20 16:04:53 2012 -0400

    Escape saved search descriptions for loc() when editing per-user Format prefs
    
    The failing tests added by 23a2160d now pass.

diff --git a/share/html/Prefs/Search.html b/share/html/Prefs/Search.html
index 0b97e31..4c0b4d6 100644
--- a/share/html/Prefs/Search.html
+++ b/share/html/Prefs/Search.html
@@ -81,7 +81,7 @@ Abort('No search specified')
 
 my $search = $class->new ($session{'CurrentUser'});
 $search->LoadById ($id);
-$title .= loc ($search->Description, loc ('"N"'));
+$title .= loc (RT::SavedSearch->EscapeDescription($search->Description), loc ('"N"'));
 my $user = $session{'CurrentUser'}->UserObj;
 my $SearchArg = $user->Preferences($search, $search->Content);
 $ARGS{Order}       = (ref $ARGS{Order}   ? join('|',grep {/\S/} @{$ARGS{Order}})   : $ARGS{Order});

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


More information about the Rt-commit mailing list