[Rt-commit] rt branch, googleish-refactor, updated. rt-3.8.5-209-g381bfc0
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Thu Oct 22 04:08:15 EDT 2009
The branch, googleish-refactor has been updated
via 381bfc0811d942f6cc1a49dca8d2134d13d86a30 (commit)
from 37752bdaf5edd05355c3425da211351a02a3aff0 (commit)
Summary of changes:
lib/RT/Search/Googleish.pm | 10 +++++--
t/web/googleish_search.t | 54 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 60 insertions(+), 4 deletions(-)
- Log -----------------------------------------------------------------
commit 381bfc0811d942f6cc1a49dca8d2134d13d86a30
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 22 16:07:34 2009 +0800
handle quotes in simple search and test for it
diff --git a/lib/RT/Search/Googleish.pm b/lib/RT/Search/Googleish.pm
index d4d7161..186a0e5 100644
--- a/lib/RT/Search/Googleish.pm
+++ b/lib/RT/Search/Googleish.pm
@@ -192,11 +192,12 @@ sub TranslateKeyValue {
my $key = shift;
my @clauses;
if ( $key =~
-/(subject|cf\.(?:[^:]*?)|content|requestor|id|status|owner|queue|fulltext):(['"])?(.+)\2?/i
+/(subject|cf\.(?:[^:]*?)|content|requestor|id|status|owner|queue|fulltext):(['"]?)(.+)\2/i
)
{
my $field = $1;
my $value = $3;
+ $value =~ s/(['"])/\\$1/g;
if ( $field =~ /id|status|owner|queue/i ) {
push @clauses, "$field = '$value'";
@@ -251,6 +252,7 @@ sub TranslateUser {
my $key = shift;
my @clauses;
if ( $key =~ /\w+\@\w+/ ) {
+ $key =~ s/(['"])/\\$1/g;
push @clauses, "Requestor LIKE '$key'";
}
return @clauses;
@@ -263,7 +265,9 @@ sub TranslateOwner {
my $User = RT::User->new( $self->TicketsObj->CurrentUser );
my ( $ret ) = $User->Load($key);
if ( $ret && $User->Privileged ) {
- push @clauses, "Owner = '" . $User->Name . "'";
+ my $name = $User->Name;
+ $name =~ s/(['"])/\\$1/g;
+ push @clauses, "Owner = '" . $name . "'";
}
return @clauses;
}
@@ -273,8 +277,8 @@ sub TranslateOthers {
my $key = shift;
my @clauses;
$key =~ s{^(['"])(.*)\1$}{$2}; # 'foo' => foo
+ $key =~ s/(['"])/\\$1/g; # foo'bar => foo\'bar
- $key =~ s/['\\].*//g; # XXX what's the usage of this?
push @clauses, "Subject LIKE '$key'";
return @clauses;
}
diff --git a/t/web/googleish_search.t b/t/web/googleish_search.t
index 91033a7..6afc2f5 100644
--- a/t/web/googleish_search.t
+++ b/t/web/googleish_search.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use RT::Test tests => 43;
+use RT::Test tests => 61;
my ($baseurl, $m) = RT::Test->started_ok;
my $url = $m->rt_base_url;
@@ -82,3 +82,55 @@ for my $q (@queries) {
$m->content_lacks( 'base ticket 2', 'base ticket 2 is not found' );
$m->content_lacks( 'not found subject', 'not found ticket is not found' );
}
+
+# now let's test with ' or "
+for my $quote ( q{'}, q{"} ) {
+ my $user = RT::User->new($RT::SystemUser);
+ is( ref($user), 'RT::User' );
+ my ( $id, $msg ) = $user->Create(
+ Name => qq!foo${quote}bar!,
+ EmailAddress => qq!foo${quote}bar$$\@example.com !,
+ Privileged => 1,
+ );
+ ok ($id, "Creating user - " . $msg );
+
+ my ( $grantid, $grantmsg ) =
+ $user->PrincipalObj->GrantRight( Right => 'OwnTicket' );
+ ok( $grantid, $grantmsg );
+
+
+
+ my $ticket_quote = RT::Ticket->new($RT::SystemUser);
+ $ticket_quote->Create(
+ Subject => qq!base${quote}ticket $$!,
+ Queue => 'general',
+ Owner => $user->Name,
+ Requestor => qq!custom${quote}search\@localhost!,
+ Content => qq!this is base${quote}ticket with quote inside!,
+ );
+ ok( $ticket_quote->id, 'created ticket with quote for custom search' );
+
+ @queries = (
+ qq!fulltext:base${quote}ticket!,
+ "base${quote}ticket",
+ "owner:foo${quote}bar",
+ "foo${quote}bar",
+
+ # email doesn't allow " character
+ $quote eq q{'}
+ ? (
+ "requestor:custom${quote}search\@localhost",
+ "custom${quote}search\@localhost",
+ )
+ : (),
+ );
+ for my $q (@queries) {
+ $m->form_with_fields('q');
+ $m->field( q => $q );
+ $m->submit;
+ my $escape_quote = $quote;
+ RT::Interface::Web::EscapeUTF8(\$escape_quote);
+ $m->content_contains( "base${escape_quote}ticket",
+ "base${quote}ticket is found" );
+ }
+}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list