debian-mirror-gitlab/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
2019-09-30 21:07:59 +05:30

39 lines
959 B
Ruby

# frozen_string_literal: true
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.gsub(/\\\//, '/')
unless Gitlab::UntrustedRegexp::RubySyntax.valid?(@value)
raise Lexer::SyntaxError, 'Invalid regular expression!'
end
end
def evaluate(variables = {})
Gitlab::UntrustedRegexp::RubySyntax.fabricate!(@value)
rescue RegexpError
raise Expression::RuntimeError, 'Invalid regular expression!'
end
def self.pattern
PATTERN
end
def self.build(string)
new(string)
end
end
end
end
end
end
end