Commit a3e6850ab9322bed6f19c60036b383cb22edccb8
1 parent
aa0f384c
Exists in
master
and in
29 other branches
pg_search_plugin: fix escape chars
Showing
2 changed files
with
7 additions
and
4 deletions
Show diff stats
plugins/pg_search/lib/ext/active_record.rb
@@ -2,11 +2,9 @@ require_dependency 'active_record' | @@ -2,11 +2,9 @@ require_dependency 'active_record' | ||
2 | 2 | ||
3 | class ActiveRecord::Base | 3 | class ActiveRecord::Base |
4 | def self.pg_search_plugin_search(query) | 4 | def self.pg_search_plugin_search(query) |
5 | - query.gsub!(/\|/,' ') | ||
6 | - formatted_query = query.split.map{|w| w += ":*"}.join('|') | ||
7 | - | 5 | + filtered_query = query.gsub(/[\|\(\)\\\/\s\[\]'"*%&!:]/,' ').split.map{|w| w += ":*"}.join('|') |
8 | if defined?(self::SEARCHABLE_FIELDS) | 6 | if defined?(self::SEARCHABLE_FIELDS) |
9 | - where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{formatted_query}')") | 7 | + where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{filtered_query}')") |
10 | else | 8 | else |
11 | raise "No searchable fields defined for #{self.name}" | 9 | raise "No searchable fields defined for #{self.name}" |
12 | end | 10 | end |
plugins/pg_search/test/unit/pg_search_plugin_test.rb
@@ -21,6 +21,11 @@ class PgSearchPluginTest < ActiveSupport::TestCase | @@ -21,6 +21,11 @@ class PgSearchPluginTest < ActiveSupport::TestCase | ||
21 | assert_includes search(Profile, 'admin deb'), profile2 | 21 | assert_includes search(Profile, 'admin deb'), profile2 |
22 | end | 22 | end |
23 | 23 | ||
24 | + should 'locate profile escaping special characters' do | ||
25 | + profile = fast_create(Profile, :name => 'John', :identifier => 'waterfall') | ||
26 | + assert_includes search(Profile, ') ( /\/\/\/\/\ o_o oOo o_o /\/\/\/\/\ ) ((tx waterfall)'), profile | ||
27 | + end | ||
28 | + | ||
24 | # TODO This feature is available only on Postgresql 9.0 | 29 | # TODO This feature is available only on Postgresql 9.0 |
25 | # http://www.postgresql.org/docs/9.0/static/unaccent.html | 30 | # http://www.postgresql.org/docs/9.0/static/unaccent.html |
26 | # should 'ignore accents' do | 31 | # should 'ignore accents' do |