Commit 118d1240 authored by Stan Hu's avatar Stan Hu

Fix 500 error caused by CODEOWNERS with no matches

Including a CODEOWNERS file with lines without any matching username or
e-mail regular expressions would cause an Error 500. Don't attempt a
database query if there is nothing to query.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/10282
parent e1707413
---
title: Fix 500 error caused by CODEOWNERS with no matches
merge_request: 26072
author:
type: fixed
......@@ -17,7 +17,11 @@ module Gitlab
def users
return User.none unless @text.present?
@users ||= User.from_union(union_relations)
relations = union_relations
return User.none unless relations.any?
@users ||= User.from_union(relations)
end
def usernames
......
......@@ -48,6 +48,14 @@ describe Gitlab::UserExtractor do
it 'includes all mentioned usernames' do
expect(extractor.matches[:usernames]).to contain_exactly('user-1', 'user-2', 'user-4')
end
context 'input has no matching e-mail or usernames' do
it 'returns an empty list of users' do
extractor = described_class.new('My test')
expect(extractor.users).to be_empty
end
end
end
describe '#references' do
......
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