gitlab-org--gitlab-foss/lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
Marius Bobin 65b20f35dc Ensure CI matching operator receives an object
Ensure the evaluation of right-hand side expression always
results in the returning of an object or an empty String
2019-08-21 18:48:16 +00:00

31 lines
734 B
Ruby

# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
module Expression
module Lexeme
class Matches < Lexeme::Operator
PATTERN = /=~/.freeze
def evaluate(variables = {})
text = @left.evaluate(variables)
regexp = @right.evaluate(variables)
return false unless regexp
regexp.scan(text.to_s).present?
end
def self.build(_value, behind, ahead)
new(behind, ahead)
end
def self.precedence
10 # See: https://ruby-doc.org/core-2.5.0/doc/syntax/precedence_rdoc.html
end
end
end
end
end
end
end