Commit ac65257c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Raise variables statement exception if pattern is invalid

parent b784a985
......@@ -11,8 +11,10 @@ module Gitlab
end
def evaluate(variables = {})
Gitlab::UntrustedRegexp.new(@value.to_s)
# TODO raise LexerError / ParserError in case of RegexpError
# TODO multiline support
@regexp = Gitlab::UntrustedRegexp.new(@value)
rescue RegexpError
raise Parser::ParserError, 'Invalid regular expression!'
end
def self.build(string)
......
......@@ -3,6 +3,8 @@ module Gitlab
module Pipeline
module Expression
class Parser
ParserError = Class.new(Statement::StatementError)
def initialize(tokens)
@tokens = tokens.to_enum
@nodes = []
......
......@@ -47,9 +47,16 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern do
describe '#evaluate' do
it 'returns a regular expression' do
string = described_class.new('abc')
regexp = described_class.new('abc')
expect(string.evaluate).to eq Gitlab::UntrustedRegexp.new('abc')
expect(regexp.evaluate).to eq Gitlab::UntrustedRegexp.new('abc')
end
it 'raises error if evaluated regexp is not valid' do
regexp = described_class.new('invalid ( .*')
expect { regexp.evaluate }
.to raise_error(Gitlab::Ci::Pipeline::Expression::Parser::ParserError)
end
end
end
require 'spec_helper'
require 'fast_spec_helper'
describe Gitlab::Ci::Pipeline::Expression::Parser do
describe '#tree' do
......
require 'spec_helper'
require 'fast_spec_helper'
describe Gitlab::Ci::Pipeline::Expression::Token do
let(:value) { '$VARIABLE' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment