Commit 44868b99 authored by Kerri Miller's avatar Kerri Miller

Merge branch '287661_lenient_iid_outofrange' into 'master'

Ignore Issue and MR IID search out of range error

See merge request gitlab-org/gitlab!49284
parents 33f49978 e9dcf27c
---
title: Ignore Issue and MR IID search out of range error
merge_request: 49284
author:
type: fixed
...@@ -67,6 +67,7 @@ module Elastic ...@@ -67,6 +67,7 @@ module Elastic
_name: context.name(self.es_type, :match, :search_terms), _name: context.name(self.es_type, :match, :search_terms),
fields: fields, fields: fields,
query: query, query: query,
lenient: true,
default_operator: default_operator default_operator: default_operator
} }
}], }],
......
...@@ -10,13 +10,9 @@ module Elastic ...@@ -10,13 +10,9 @@ module Elastic
if query =~ /#(\d+)\z/ if query =~ /#(\d+)\z/
iid_query_hash(Regexp.last_match(1)) iid_query_hash(Regexp.last_match(1))
else else
fields = %w(title^2 description) # iid field can be added here as lenient option will
# pardon format errors, like integer out of range.
# We can only allow searching the iid field if the query is fields = %w(iid^3 title^2 description)
# just a number, otherwise Elasticsearch will error since this
# field is type integer.
fields << "iid^3" if query =~ /\A\d+\z/
basic_query_hash(fields, query) basic_query_hash(fields, query)
end end
......
...@@ -10,13 +10,9 @@ module Elastic ...@@ -10,13 +10,9 @@ module Elastic
if query =~ /\!(\d+)\z/ if query =~ /\!(\d+)\z/
iid_query_hash(Regexp.last_match(1)) iid_query_hash(Regexp.last_match(1))
else else
fields = %w(title^2 description) # iid field can be added here as lenient option will
# pardon format errors, like integer out of range.
# We can only allow searching the iid field if the query is fields = %w(iid^3 title^2 description)
# just a number, otherwise Elasticsearch will error since this
# field is type integer.
fields << "iid^3" if query =~ /\A\d+\z/
basic_query_hash(fields, query) basic_query_hash(fields, query)
end end
......
...@@ -204,7 +204,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need ...@@ -204,7 +204,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
describe 'issues' do describe 'issues' do
let(:scope) { 'issues' } let(:scope) { 'issues' }
let!(:issue_1) { create(:issue, project: project_1, title: 'Hello world, here I am!', iid: 1) } let!(:issue_1) { create(:issue, project: project_1, title: 'Hello world, here I am!', description: '20200623170000, see details in issue 287661', iid: 1) }
let!(:issue_2) { create(:issue, project: project_1, title: 'Issue Two', description: 'Hello world, here I am!', iid: 2) } let!(:issue_2) { create(:issue, project: project_1, title: 'Issue Two', description: 'Hello world, here I am!', iid: 2) }
let!(:issue_3) { create(:issue, project: project_2, title: 'Issue Three', iid: 2) } let!(:issue_3) { create(:issue, project: project_2, title: 'Issue Three', iid: 2) }
...@@ -245,6 +245,14 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need ...@@ -245,6 +245,14 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
expect(results.issues_count).to eq 1 expect(results.issues_count).to eq 1
end end
it 'finds the issue with an out of integer range number in its description without exception' do
results = described_class.new(user, '20200623170000', limit_project_ids, public_and_internal_projects: false)
issues = results.objects('issues')
expect(issues).to contain_exactly(issue_1)
expect(results.issues_count).to eq 1
end
it 'returns empty list when search by invalid iid' do it 'returns empty list when search by invalid iid' do
results = described_class.new(user, '#222', limit_project_ids) results = described_class.new(user, '#222', limit_project_ids)
...@@ -546,6 +554,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need ...@@ -546,6 +554,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
source_project: project_1, source_project: project_1,
target_project: project_1, target_project: project_1,
title: 'Hello world, here I am!', title: 'Hello world, here I am!',
description: '20200623170000, see details in issue 287661',
iid: 1 iid: 1
) )
@merge_request_2 = create( @merge_request_2 = create(
...@@ -601,6 +610,14 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need ...@@ -601,6 +610,14 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
expect(results.merge_requests_count).to eq 1 expect(results.merge_requests_count).to eq 1
end end
it 'finds the MR with an out of integer range number in its description without exception' do
results = described_class.new(user, '20200623170000', limit_project_ids, public_and_internal_projects: false)
merge_requests = results.objects('merge_requests')
expect(merge_requests).to contain_exactly(@merge_request_1)
expect(results.merge_requests_count).to eq 1
end
it 'returns empty list when search by invalid iid' do it 'returns empty list when search by invalid iid' do
results = described_class.new(user, '#222', limit_project_ids) results = described_class.new(user, '#222', limit_project_ids)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment