[Rt-commit] rt branch, 4.0/loc-escape-squares, created. rt-4.0.8-115-g31269e1

? sunnavy sunnavy at bestpractical.com
Mon Nov 5 19:35:01 EST 2012


The branch, 4.0/loc-escape-squares has been created
        at  31269e198ed2de2002bf55d9f9f857950955abea (commit)

- Log -----------------------------------------------------------------
commit b4aff021d431df0d31b23240081c115b48c72f43
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Jan 9 20:19:06 2012 +0800

    "[" and "]" need to be escaped in loc
    
    otherwise it's impossible to translate "[Up]" or "[Down]" in .po files
    see also #19218

diff --git a/share/html/Elements/RT__CustomField/ColumnMap b/share/html/Elements/RT__CustomField/ColumnMap
index b043984..48931e6 100644
--- a/share/html/Elements/RT__CustomField/ColumnMap
+++ b/share/html/Elements/RT__CustomField/ColumnMap
@@ -162,10 +162,10 @@ my $COLUMN_MAP = {
             my @res = (
                 \'<a href="',
                 $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveCustomFieldUp => $id ),
-                \'">', loc('[Up]'), \'</a>',
+                \'">', loc('~[Up~]'), \'</a>',
                 \' <a href="',
                 $uri .'?'. $m->comp("/Elements/QueryString", %pass, MoveCustomFieldDown => $id ),
-                \'">', loc('[Down]'), \'</a>'
+                \'">', loc('~[Down~]'), \'</a>'
             );
 
             return @res;

commit 178dd6f2a1fa606ea497947ffda420d2715b9a73
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 30 18:50:22 2012 +0800

    return the unescaped string if it's not in .po
    
    this fixes the bug that returns "~[Up~]" instead of the right "[Up]"

diff --git a/lib/RT/CurrentUser.pm b/lib/RT/CurrentUser.pm
index 7d24779..dcb2683 100644
--- a/lib/RT/CurrentUser.pm
+++ b/lib/RT/CurrentUser.pm
@@ -240,9 +240,12 @@ sub loc {
     my $handle = $self->LanguageHandle;
 
     if (@_ == 1) {
-        # pre-scan the lexicon hashes to return _AUTO keys verbatim,
-        # to keep locstrings containing '[' and '~' from tripping over Maketext
-        return $_[0] unless grep exists $_->{$_[0]}, @{ $handle->_lex_refs };
+        # If we have no [_1] replacements, and the key does not appear
+        # in the lexicon, unescape (using ~) and return it verbatim, as
+        # an optimization.
+        my $unescaped = $_[0];
+        $unescaped =~ s!~(.)!$1!g;
+        return $unescaped unless grep exists $_->{$_[0]}, @{ $handle->_lex_refs };
     }
 
     return $handle->maketext(@_);

commit 292ac539c6fb4922eab67b681bd843c61678f05d
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 8db89a5..ee5e9f5 100644
--- a/t/web/custom_frontpage.t
+++ b/t/web/custom_frontpage.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-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 e3a2ea8b8bca78dde8740ca91ebcf6f7acf5b148
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 f7695d6..18f263b 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 4b96bbf..982d42c 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 31269e198ed2de2002bf55d9f9f857950955abea
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 42aa16b..bc52fe7 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