[Rt-commit] rt branch, 4.2/warn-on-case-sensitive-searches, created. rt-4.1.8-153-gc29fadc
Ruslan Zakirov
ruz at bestpractical.com
Fri Apr 19 10:24:33 EDT 2013
The branch, 4.2/warn-on-case-sensitive-searches has been created
at c29fadc3d9af2b62b5f41e914436f452d9619dcf (commit)
- Log -----------------------------------------------------------------
commit c29fadc3d9af2b62b5f41e914436f452d9619dcf
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Apr 18 22:01:27 2013 +0400
warn on case sensitive searches
Because of historical reasons RT's searches
marked as case sensitive in RT::SearchBuilder::Limit, but we
expect them to be case insensitive.
Mixing case sensitive and case insensitive searches by the same
column causes problems for some columns on Pg and Oracle. Especially
those that should be indexed as indexes are different depending on
search kind.
This code catches such cases and throws a warning.
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index 48e571d..429f1be 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -130,7 +130,7 @@ sub LimitToGrouping {
return $self->Limit( FIELD => 'id', VALUE => 0, ENTRYAGGREGATOR => 'AND' );
}
foreach ( @$list ) {
- $self->Limit( FIELD => 'Name', VALUE => $_ );
+ $self->Limit( FIELD => 'Name', VALUE => $_, CASESENSITIVE => 0 );
}
} else {
my @list = map {@$_} grep defined && ref($_) eq 'ARRAY',
@@ -143,6 +143,7 @@ sub LimitToGrouping {
OPERATOR => '!=',
VALUE => $_,
ENTRYAGGREGATOR => 'AND',
+ CASESENSITIVE => 0,
);
}
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 70a5f58..4051e6b 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3452,7 +3452,7 @@ sub GetPrincipalsMap {
my $class = $object->RecordClassFromLookupType;
if ($class and $class->DOES("RT::Record::Role::Roles")) {
$roles->LimitToRolesForObject(RT->System);
- $roles->Limit( FIELD => "Name", VALUE => $_ )
+ $roles->Limit( FIELD => "Name", VALUE => $_, CASESENSITIVE => 0 )
for $class->Roles;
} else {
# No roles to show; so show nothing
diff --git a/lib/RT/SearchBuilder.pm b/lib/RT/SearchBuilder.pm
index 135e59b..383cca3 100644
--- a/lib/RT/SearchBuilder.pm
+++ b/lib/RT/SearchBuilder.pm
@@ -254,6 +254,13 @@ injection attacks when we pass through user specified values.
=cut
+my %check_case_sensitivity = (
+ groups => { 'name' => 1 },
+ queues => { 'name' => 1 },
+ users => { 'name' => 1, emailaddress => 1 },
+ customfields => { 'name' => 1 },
+);
+
my %deprecated = (
groups => {
type => 'Name',
@@ -264,7 +271,6 @@ my %deprecated = (
sub Limit {
my $self = shift;
my %ARGS = (
- CASESENSITIVE => 1,
OPERATOR => '=',
@_,
);
@@ -308,6 +314,16 @@ sub Limit {
);
}
+ unless ( exists $ARGS{CASESENSITIVE} ) {
+ if ( $table && $check_case_sensitivity{ lc $table }{ lc $ARGS{'FIELD'} } ) {
+ RT->Logger->warning(
+ "Case sensitive search by $table.$ARGS{'FIELD'}"
+ ." at ". (caller)[1] . " line ". (caller)[2]
+ );
+ }
+ $ARGS{'CASESENSITIVE'} = 1;
+ }
+
return $self->SUPER::Limit( %ARGS );
}
diff --git a/lib/RT/SearchBuilder/Role/Roles.pm b/lib/RT/SearchBuilder/Role/Roles.pm
index d06526a..7b89244 100644
--- a/lib/RT/SearchBuilder/Role/Roles.pm
+++ b/lib/RT/SearchBuilder/Role/Roles.pm
@@ -137,6 +137,7 @@ sub _RoleGroupsJoin {
ALIAS => $groups,
FIELD => 'Name',
VALUE => $name,
+ CASESENSITIVE => 0,
) if $name;
$self->{'_sql_role_group_aliases'}{ $args{'Class'} .'-'. $name } = $groups
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 23bb062..2767167 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -1064,7 +1064,7 @@ sub _CustomFieldDecipher {
elsif ( $field =~ /\D/ ) {
$queue = '';
my $cfs = RT::CustomFields->new( $self->CurrentUser );
- $cfs->Limit( FIELD => 'Name', VALUE => $field );
+ $cfs->Limit( FIELD => 'Name', VALUE => $field, CASESENSITIVE => 0 );
$cfs->LimitToLookupType('RT::Queue-RT::Ticket');
# if there is more then one field the current user can
@@ -2938,7 +2938,7 @@ sub CurrentUserCanSee {
my $groups = RT::Groups->new( RT->SystemUser );
$groups->Limit( FIELD => 'Domain', VALUE => 'RT::Queue-Role' );
foreach ( @tmp ) {
- $groups->Limit( FIELD => 'Name', VALUE => $_ );
+ $groups->Limit( FIELD => 'Name', VALUE => $_, CASESENSITIVE => 0 );
}
my $principal_alias = $groups->Join(
ALIAS1 => 'main',
@@ -3044,6 +3044,7 @@ sub CurrentUserCanSee {
FIELD => 'Name',
VALUE => $role,
ENTRYAGGREGATOR => 'AND',
+ CASESENSITIVE => 0,
);
}
$limit_queues->( 'AND', @$queues ) if ref $queues;
diff --git a/share/html/Admin/Groups/Modify.html b/share/html/Admin/Groups/Modify.html
index 7cf046a..e9c404c 100644
--- a/share/html/Admin/Groups/Modify.html
+++ b/share/html/Admin/Groups/Modify.html
@@ -136,7 +136,7 @@ if ($Group->Id) {
# Warn about duplicate groups
my $dupcheck = RT::Groups->new(RT->SystemUser);
$dupcheck->LimitToUserDefinedGroups();
- $dupcheck->Limit( FIELD => 'Name', VALUE => $Group->Name );
+ $dupcheck->Limit( FIELD => 'Name', VALUE => $Group->Name, CASESENSITIVE => 0 );
if ($dupcheck->Count > 1) {
push @warnings, loc("There is more than one group with the name '[_1]'. This may cause inconsistency in parts of the admin interface, and therefore it's recommended you rename the conflicting groups.", $Group->Name);
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list