From 937630bb8eb0d85bf02655df29e954d32ce7e26b Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 27 Mar 2018 14:46:58 +0200 Subject: [PATCH] Do not raise when validating variables expression --- lib/gitlab/ci/config/entry/policy.rb | 2 +- lib/gitlab/ci/pipeline/expression/statement.rb | 4 ---- spec/lib/gitlab/ci/config/entry/policy_spec.rb | 10 +++++++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/gitlab/ci/config/entry/policy.rb b/lib/gitlab/ci/config/entry/policy.rb index b6d137a7e68..09e8e52b60f 100644 --- a/lib/gitlab/ci/config/entry/policy.rb +++ b/lib/gitlab/ci/config/entry/policy.rb @@ -47,7 +47,7 @@ module Gitlab statements.each do |statement| unless statement.valid? - errors.add(:variables, "Invalid expression #{statement.inspect}") + errors.add(:variables, "Invalid expression syntax") end end end diff --git a/lib/gitlab/ci/pipeline/expression/statement.rb b/lib/gitlab/ci/pipeline/expression/statement.rb index b04576f7978..09a7c98464b 100644 --- a/lib/gitlab/ci/pipeline/expression/statement.rb +++ b/lib/gitlab/ci/pipeline/expression/statement.rb @@ -37,10 +37,6 @@ module Gitlab evaluate.present? end - def inspect - "syntax: #{@lexer.lexemes.join(' ')}" - end - def valid? parse_tree.is_a?(Lexeme::Base) rescue StatementError diff --git a/spec/lib/gitlab/ci/config/entry/policy_spec.rb b/spec/lib/gitlab/ci/config/entry/policy_spec.rb index f06d3a13ce0..08718c382b9 100644 --- a/spec/lib/gitlab/ci/config/entry/policy_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/policy_spec.rb @@ -104,7 +104,15 @@ describe Gitlab::Ci::Config::Entry::Policy do let(:config) { { variables: ['$MY_VAR =='] } } it 'reports an error about invalid statement' do - expect(entry.errors).to include /invalid expression syntax: variable equals/ + expect(entry.errors).to include /invalid expression syntax/ + end + end + + context 'when specifying invalid variables expressions token' do + let(:config) { { variables: ['$MY_VAR == 123'] } } + + it 'reports an error about invalid statement' do + expect(entry.errors).to include /invalid expression syntax/ end end