[Rt-commit] rt branch, 4.0/loc-escape-squares, created. rt-4.0.8-115-g55fbf79
Alex Vandiver
alexmv at bestpractical.com
Fri Nov 2 20:11:38 EDT 2012
The branch, 4.0/loc-escape-squares has been created
at 55fbf79f5080c79368012b0aee5fffaffb4ed4bf (commit)
- Log -----------------------------------------------------------------
commit 53199c4dbe813fb1fdc3f56e7d054e4d0d73a8e3
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Jan 9 20:19:06 2012 +0800
"[" and "]" need to be escaped in loc
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 c4d8f302806544e6bc550f5dd2e5b2baabba4597
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 a455163b5408c78a365c8480cd414fb69541e747
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 54abc45d716f306e3a99647a0169d7a1d7294122
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 55fbf79f5080c79368012b0aee5fffaffb4ed4bf
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