summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-14 14:38:08 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-05-14 14:38:08 +0200
commitac65257c40052f739492f0648f6b7c06a1c95250 (patch)
tree66b04fd9432e3b479666b7680a6d0c8a6e1420ab
parentb784a985f2188e328da32cc9fdc73c8d4ac63733 (diff)
downloadgitlab-ce-ac65257c40052f739492f0648f6b7c06a1c95250.tar.gz
Raise variables statement exception if pattern is invalid
-rw-r--r--lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb6
-rw-r--r--lib/gitlab/ci/pipeline/expression/parser.rb2
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb11
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/token_spec.rb2
5 files changed, 17 insertions, 6 deletions
diff --git a/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb b/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
index 8cb1af30252..2ff527e34a8 100644
--- a/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
+++ b/lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
@@ -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)
diff --git a/lib/gitlab/ci/pipeline/expression/parser.rb b/lib/gitlab/ci/pipeline/expression/parser.rb
index 90f94d0b763..fe23ab0b2f8 100644
--- a/lib/gitlab/ci/pipeline/expression/parser.rb
+++ b/lib/gitlab/ci/pipeline/expression/parser.rb
@@ -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 = []
diff --git a/spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
index b7998b512f5..ed69742cd7c 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
@@ -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
diff --git a/spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
index e8e6f585310..2b78b1dd4a7 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require 'fast_spec_helper'
describe Gitlab::Ci::Pipeline::Expression::Parser do
describe '#tree' do
diff --git a/spec/lib/gitlab/ci/pipeline/expression/token_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/token_spec.rb
index 6d7453f0de5..cedfe270f9d 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/token_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/token_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require 'fast_spec_helper'
describe Gitlab::Ci::Pipeline::Expression::Token do
let(:value) { '$VARIABLE' }