From a3e6850ab9322bed6f19c60036b383cb22edccb8 Mon Sep 17 00:00:00 2001 From: Francisco Marcelo de Araújo Lima Júnior Date: Fri, 7 Feb 2014 11:27:29 -0300 Subject: [PATCH] pg_search_plugin: fix escape chars --- plugins/pg_search/lib/ext/active_record.rb | 6 ++---- plugins/pg_search/test/unit/pg_search_plugin_test.rb | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/pg_search/lib/ext/active_record.rb b/plugins/pg_search/lib/ext/active_record.rb index 89b9a4d..6b8712d 100644 --- a/plugins/pg_search/lib/ext/active_record.rb +++ b/plugins/pg_search/lib/ext/active_record.rb @@ -2,11 +2,9 @@ require_dependency 'active_record' class ActiveRecord::Base def self.pg_search_plugin_search(query) - query.gsub!(/\|/,' ') - formatted_query = query.split.map{|w| w += ":*"}.join('|') - + filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') if defined?(self::SEARCHABLE_FIELDS) - where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{formatted_query}')") + where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')") else raise "No searchable fields defined for #{self.name}" end diff --git a/plugins/pg_search/test/unit/pg_search_plugin_test.rb b/plugins/pg_search/test/unit/pg_search_plugin_test.rb index 327bfab..6069f37 100644 --- a/plugins/pg_search/test/unit/pg_search_plugin_test.rb +++ b/plugins/pg_search/test/unit/pg_search_plugin_test.rb @@ -21,6 +21,11 @@ class PgSearchPluginTest < ActiveSupport::TestCase assert_includes search(Profile, 'admin deb'), profile2 end + should 'locate profile escaping special characters' do + profile = fast_create(Profile, :name => 'John', :identifier => 'waterfall') + assert_includes search(Profile, ') ( /\/\/\/\/\ o_o oOo o_o /\/\/\/\/\ ) ((tx waterfall)'), profile + end + # TODO This feature is available only on Postgresql 9.0 # http://www.postgresql.org/docs/9.0/static/unaccent.html # should 'ignore accents' do -- libgit2 0.21.2