Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot
2025-05-29 03:07:24 +00:00
parent e1ff0ac4f3
commit 0ac5e597b9
5 changed files with 87 additions and 14 deletions

View File

@ -1 +1 @@
cb864608c0a939bcbf4700a322acfbc89c76f26a
d6976fb71618881bfda4075ae453729ca29c23a3

View File

@ -1,9 +0,0 @@
---
name: duo_code_review_multi_file
feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/532653
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/188117
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/536005
milestone: '18.0'
group: group::code review
type: beta
default_enabled: true

View File

@ -45,7 +45,7 @@ module Ci
safe_regex = ::Gitlab::UntrustedRegexp.new(regex)
return if safe_regex.match?(value)
return if safe_regex.match?(value, allow_empty_string: true)
error("#{default ? 'default' : 'provided'} value does not match required RegEx pattern")
rescue RegexpError

View File

@ -74,8 +74,10 @@ module Gitlab
scan_regexp.match(text)
end
def match?(text)
text.present? && scan(text).present?
def match?(text, allow_empty_string: false)
return false if text.nil?
(allow_empty_string || text.present?) && scan(text).present?
end
def replace(text, rewrite)

View File

@ -109,7 +109,7 @@ RSpec.describe Gitlab::UntrustedRegexp, feature_category: :shared do
let(:regexp) { 'foo' }
let(:text) { 'foo' }
it 'returns an array of nil matches' do
it 'returns an array of matches' do
is_expected.to eq(true)
end
end
@ -122,6 +122,86 @@ RSpec.describe Gitlab::UntrustedRegexp, feature_category: :shared do
is_expected.to eq(false)
end
end
context 'when nil is passed' do
let(:regexp) { '\w{0,2}' }
let(:text) { nil }
it { is_expected.to eq(false) }
end
context 'when nil is passed with allow_empty_string' do
subject { create_regex(regexp).match?(text, allow_empty_string: true) }
let(:regexp) { '\w{0,2}' }
let(:text) { nil }
it { is_expected.to eq(false) }
end
context 'when a matching empty string is passed' do
let(:regexp) { '\w{0,2}' }
let(:text) { '' }
it { is_expected.to eq(false) }
end
context 'when a matching empty string is passed is passed with allow_empty_string' do
subject { create_regex(regexp).match?(text, allow_empty_string: true) }
let(:regexp) { '\w{0,2}' }
let(:text) { '' }
it { is_expected.to eq(true) }
end
context 'when a matching string only containing spaces is passed' do
let(:regexp) { '^\s{0,2}$' }
let(:text) { ' ' }
it { is_expected.to eq(false) }
end
context 'when a matching string only containing spaces is passed with allow_empty_string' do
subject { create_regex(regexp).match?(text, allow_empty_string: true) }
let(:regexp) { '^\s{0,2}$' }
let(:text) { ' ' }
it { is_expected.to eq(true) }
end
context 'when a non-matching empty string is passed' do
let(:regexp) { '\w{1,2}' }
let(:text) { '' }
it { is_expected.to eq(false) }
end
context 'when a non-matching empty string is passed is passed with allow_empty_string' do
subject { create_regex(regexp).match?(text, allow_empty_string: true) }
let(:regexp) { '\w{1,2}' }
let(:text) { '' }
it { is_expected.to eq(false) }
end
context 'when a non-matching string only containing spaces is passed' do
let(:regexp) { '^\s{2,4}$' }
let(:text) { ' ' }
it { is_expected.to eq(false) }
end
context 'when a non-matching string only containing spaces is passed with allow_empty_string' do
subject { create_regex(regexp).match?(text, allow_empty_string: true) }
let(:regexp) { '^\s{2,4}$' }
let(:text) { ' ' }
it { is_expected.to eq(false) }
end
end
describe '#scan' do