summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMarius Bobin <mbobin@gitlab.com>2019-08-13 13:27:34 +0300
committerMarius Bobin <mbobin@gitlab.com>2019-08-21 14:34:19 +0300
commitc5e73017f49a5a5980b41f2ff2baec7ed0517732 (patch)
tree7643e66f81d335a8c50d69a14318c4244f3728ce /spec
parenta328c8fdcd41a25b928f7cd18ad616f14f97a37a (diff)
downloadgitlab-ce-c5e73017f49a5a5980b41f2ff2baec7ed0517732.tar.gz
Pattern matching empty values follow Ruby behavior64383-pattern-matching-with-variables-causes-gitlabs-ci-lint-to-throw-500
Replace Array#any? and Array#none? with Array#present? and Array#empty? so that arrays with nil elements count as matches. Ruby behavior: '' =~ // # => 0 '' !~ // # => false Our operator with empty values: regexp.scan(text.to_s) # => [nil]
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb14
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/lexeme/not_matches_spec.rb14
2 files changed, 28 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
index d41b97742bf..a527783ffac 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
@@ -83,6 +83,20 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do
it { is_expected.to eq(false) }
end
+ context 'when left is an empty string' do
+ let(:left_value) { '' }
+ let(:right_value) { Gitlab::UntrustedRegexp.new('pattern') }
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'when left and right are empty strings' do
+ let(:left_value) { '' }
+ let(:right_value) { Gitlab::UntrustedRegexp.new('') }
+
+ it { is_expected.to eq(true) }
+ end
+
context 'when left is a multiline string and matches right' do
let(:left_value) do
<<~TEXT
diff --git a/spec/lib/gitlab/ci/pipeline/expression/lexeme/not_matches_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/lexeme/not_matches_spec.rb
index 20bab73244a..fb4238ecaf3 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/lexeme/not_matches_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/lexeme/not_matches_spec.rb
@@ -83,6 +83,20 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::NotMatches do
it { is_expected.to eq(true) }
end
+ context 'when left is an empty string' do
+ let(:left_value) { '' }
+ let(:right_value) { Gitlab::UntrustedRegexp.new('pattern') }
+
+ it { is_expected.to eq(true) }
+ end
+
+ context 'when left and right are empty strings' do
+ let(:left_value) { '' }
+ let(:right_value) { Gitlab::UntrustedRegexp.new('') }
+
+ it { is_expected.to eq(false) }
+ end
+
context 'when left is a multiline string and matches right' do
let(:left_value) do
<<~TEXT