Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-13 18:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-13 18:07:43 +0300
commit7eca3f56625526ffa7f263c1fef0fcea34de8ca6 (patch)
treefec87c2a902e3c44f89963f4b28e6de32c0806f3 /lib/gitlab/ci/pipeline
parent988424215cf104d9ee24bb1751141424cffb32d1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/ci/pipeline')
-rw-r--r--lib/gitlab/ci/pipeline/expression/lexeme/matches.rb7
-rw-r--r--lib/gitlab/ci/pipeline/expression/lexeme/not_matches.rb7
-rw-r--r--lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb12
-rw-r--r--lib/gitlab/ci/pipeline/expression/lexeme/value.rb2
4 files changed, 28 insertions, 0 deletions
diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb b/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
index 4d65b914d8d..6efb3a4f16a 100644
--- a/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
+++ b/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
@@ -11,8 +11,15 @@ module Gitlab
def evaluate(variables = {})
text = @left.evaluate(variables)
regexp = @right.evaluate(variables)
+
return false unless regexp
+ if ::Feature.enabled?(:ci_fix_rules_if_comparison_with_regexp_variable)
+ # All variables are evaluated as strings, even if they are regexp strings.
+ # So, we need to convert them to regexp objects.
+ regexp = Lexeme::Pattern.build_and_evaluate(regexp, variables)
+ end
+
regexp.scan(text.to_s).present?
end
diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/not_matches.rb b/lib/gitlab/ci/pipeline/expression/lexeme/not_matches.rb
index 29c5aa5d753..a72e5dbc822 100644
--- a/lib/gitlab/ci/pipeline/expression/lexeme/not_matches.rb
+++ b/lib/gitlab/ci/pipeline/expression/lexeme/not_matches.rb
@@ -11,8 +11,15 @@ module Gitlab
def evaluate(variables = {})
text = @left.evaluate(variables)
regexp = @right.evaluate(variables)
+
return true unless regexp
+ if ::Feature.enabled?(:ci_fix_rules_if_comparison_with_regexp_variable)
+ # All variables are evaluated as strings, even if they are regexp strings.
+ # So, we need to convert them to regexp objects.
+ regexp = Lexeme::Pattern.build_and_evaluate(regexp, variables)
+ end
+
regexp.scan(text.to_s).empty?
end
diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb b/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
index c7106f3ec39..cd4106b16bb 100644
--- a/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
+++ b/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
@@ -35,6 +35,18 @@ module Gitlab
def self.build(string)
new(string)
end
+
+ def self.build_and_evaluate(data, variables = {})
+ return data if data.is_a?(Gitlab::UntrustedRegexp)
+
+ begin
+ new_pattern = build(data)
+ rescue Lexer::SyntaxError
+ return data
+ end
+
+ new_pattern.evaluate(variables)
+ end
end
end
end
diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/value.rb b/lib/gitlab/ci/pipeline/expression/lexeme/value.rb
index 6d872fee39d..fa82bbe3275 100644
--- a/lib/gitlab/ci/pipeline/expression/lexeme/value.rb
+++ b/lib/gitlab/ci/pipeline/expression/lexeme/value.rb
@@ -10,6 +10,8 @@ module Gitlab
:value
end
+ attr_reader :value
+
def initialize(value)
@value = value
end