diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /lib/gitlab/search/params.rb | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'lib/gitlab/search/params.rb')
-rw-r--r-- | lib/gitlab/search/params.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/gitlab/search/params.rb b/lib/gitlab/search/params.rb index e6a1305a82a..1ae14e5e618 100644 --- a/lib/gitlab/search/params.rb +++ b/lib/gitlab/search/params.rb @@ -7,6 +7,7 @@ module Gitlab SEARCH_CHAR_LIMIT = 4096 SEARCH_TERM_LIMIT = 64 + MIN_TERM_LENGTH = 3 # Generic validation validates :query_string, length: { maximum: SEARCH_CHAR_LIMIT } @@ -53,6 +54,10 @@ module Gitlab errors[:query_string].none? { |msg| msg.include? SEARCH_TERM_LIMIT.to_s } end + def email_lookup? + search_terms.any? { |term| term =~ URI::MailTo::EMAIL_REGEXP } + end + def validate if detect_abuse? abuse_detection.validate @@ -75,8 +80,12 @@ module Gitlab @detect_abuse end + def search_terms + @search_terms ||= query_string.split.select { |word| word.length >= MIN_TERM_LENGTH } + end + def not_too_many_terms - if query_string.split.count { |word| word.length >= 3 } > SEARCH_TERM_LIMIT + if search_terms.count > SEARCH_TERM_LIMIT errors.add :query_string, "has too many search terms (maximum is #{SEARCH_TERM_LIMIT})" end end |