[Rt-commit] rt branch 5.0/oracle-escape-fts-terms created. rt-5.0.5-157-gd10f9d95e8

BPS Git Server git at git.bestpractical.com
Thu Feb 8 21:30:50 UTC 2024


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/oracle-escape-fts-terms has been created
        at  d10f9d95e893886c9081687306269a64ac43887e (commit)

- Log -----------------------------------------------------------------
commit d10f9d95e893886c9081687306269a64ac43887e
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Feb 8 16:03:04 2024 -0500

    Automatically escape fulltext search terms for Oracle
    
    This is usually what user really means. Without it, searching reserved words
    like "about" would break the search.

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 275fe6653a..97b2c50b45 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -994,6 +994,10 @@ sub _TransContentLimit {
         if ( $db_type eq 'Oracle' ) {
             my $dbh = $RT::Handle->dbh;
             my $alias = $self->{_sql_trattachalias};
+
+            # Automatically escape values
+            $value = "{$value}" unless $value =~ /^\{.*\}$/;
+
             $self->Limit(
                 %rest,
                 FUNCTION      => "CONTAINS( $alias.$field, ".$dbh->quote($value) .")",
diff --git a/lib/RT/Transactions.pm b/lib/RT/Transactions.pm
index e03d2995a8..216dc5a462 100644
--- a/lib/RT/Transactions.pm
+++ b/lib/RT/Transactions.pm
@@ -738,6 +738,10 @@ sub _AttachContentLimit {
         if ( $db_type eq 'Oracle' ) {
             my $dbh = $RT::Handle->dbh;
             my $alias = $self->{_sql_aliases}{attach};
+
+            # Automatically escape values
+            $value = "{$value}" unless $value =~ /^\{.*\}$/;
+
             $self->Limit(
                 %rest,
                 FUNCTION      => "CONTAINS( $alias.$field, ".$dbh->quote($value) .")",
diff --git a/t/fts/indexed_oracle.t b/t/fts/indexed_oracle.t
index a5b15bd825..fabcdffdf5 100644
--- a/t/fts/indexed_oracle.t
+++ b/t/fts/indexed_oracle.t
@@ -4,7 +4,6 @@ use warnings;
 
 use RT::Test tests => undef;
 plan skip_all => 'Not Oracle' unless RT->Config->Get('DatabaseType') eq 'Oracle';
-plan tests => 13;
 
 RT->Config->Set( FullTextSearch => Enable => 1, Indexed => 1, IndexName => 'rt_fts_index' );
 
@@ -69,13 +68,18 @@ sub run_test {
     { Queue => $q->id },
     { Subject => 'book', Content => 'book' },
     { Subject => 'bar', Content => 'bar' },
+    { Subject => 'hyphen', Content => 'post-modern' },
+    { Subject => 'reserved', Content => 'about' },
 );
 sync_index();
 
 run_tests(
-    "Content LIKE 'book'" => { book => 1, bar => 0 },
-    "Content LIKE 'bar'" => { book => 0, bar => 1 },
+    "Content LIKE 'book'" => { book => 1, bar => 0, hyphen => 0, reserved => 0 },
+    "Content LIKE 'bar'" => { book => 0, bar => 1, hyphen => 0, reserved => 0 },
+    "Content LIKE 'post-modern'" => { book => 0, bar => 0, hyphen => 1, reserved => 0 },
+    "Content LIKE 'about'" => { book => 0, bar => 0, hyphen => 0, reserved => 1 },
 );
 
 @tickets = ();
 
+done_testing;

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list