diff options
-rw-r--r-- | app/models/concerns/pg_full_text_searchable.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/pg_full_text_searchable_spec.rb | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/app/models/concerns/pg_full_text_searchable.rb b/app/models/concerns/pg_full_text_searchable.rb index b7ca6f61573..b31a52f98ca 100644 --- a/app/models/concerns/pg_full_text_searchable.rb +++ b/app/models/concerns/pg_full_text_searchable.rb @@ -26,6 +26,7 @@ module PgFullTextSearchable TEXT_SEARCH_DICTIONARY = 'english' URL_SCHEME_REGEX = %r{(?<=\A|\W)\w+://(?=\w+)} TSQUERY_DISALLOWED_CHARACTERS_REGEX = %r{[^a-zA-Z0-9 .@/\-_"]} + XML_TAG_REGEX = %r{</?([^>]+)>} def update_search_data! tsvector_sql_nodes = self.class.pg_full_text_searchable_columns.map do |column, weight| @@ -55,6 +56,7 @@ module PgFullTextSearchable column_text = self[column].gsub(LONG_WORDS_REGEX, ' ') column_text = column_text[0..(TSVECTOR_MAX_LENGTH - 1)] column_text = ActiveSupport::Inflector.transliterate(column_text) + column_text = column_text.gsub(XML_TAG_REGEX, ' \1 ') Arel::Nodes::NamedFunction.new( 'setweight', diff --git a/spec/models/concerns/pg_full_text_searchable_spec.rb b/spec/models/concerns/pg_full_text_searchable_spec.rb index 8e3b65cf125..7da48489e12 100644 --- a/spec/models/concerns/pg_full_text_searchable_spec.rb +++ b/spec/models/concerns/pg_full_text_searchable_spec.rb @@ -146,6 +146,16 @@ RSpec.describe PgFullTextSearchable, feature_category: :global_search do expect(model_class.pg_full_text_search('123')).to contain_exactly(with_dash) end end + + context 'when text has XML tags' do + let(:with_xml) { model_class.create!(project: project, namespace: project.project_namespace, title: '<rain>go away</rain>', description: 'description') } + + it 'removes XML tag syntax' do + with_xml.update_search_data! + + expect(model_class.pg_full_text_search('rain')).to contain_exactly(with_xml) + end + end end describe '#update_search_data!' do |