2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Pipeline
|
|
|
|
module Expression
|
|
|
|
module Lexeme
|
|
|
|
require_dependency 're2'
|
|
|
|
|
|
|
|
class Pattern < Lexeme::Value
|
|
|
|
PATTERN = %r{^/.+/[ismU]*$}.freeze
|
|
|
|
|
|
|
|
def initialize(regexp)
|
|
|
|
@value = regexp
|
|
|
|
|
2019-04-03 18:18:56 +05:30
|
|
|
unless Gitlab::UntrustedRegexp::RubySyntax.valid?(@value)
|
2018-11-08 19:23:39 +05:30
|
|
|
raise Lexer::SyntaxError, 'Invalid regular expression!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def evaluate(variables = {})
|
2019-04-03 18:18:56 +05:30
|
|
|
Gitlab::UntrustedRegexp::RubySyntax.fabricate!(@value)
|
2018-11-08 19:23:39 +05:30
|
|
|
rescue RegexpError
|
|
|
|
raise Expression::RuntimeError, 'Invalid regular expression!'
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.build(string)
|
|
|
|
new(string)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|