mirror of
https://gitlab.com/gitlab-org/gitlab-foss.git
synced 2025-07-29 12:00:32 +00:00
Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
@ -1 +1 @@
|
||||
cb864608c0a939bcbf4700a322acfbc89c76f26a
|
||||
d6976fb71618881bfda4075ae453729ca29c23a3
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user