Commit f91282c9 authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch '64383-pattern-matching-with-variables-causes-gitlabs-ci-lint-to-throw-500' into 'master'

Fix 500 errors caused by pattern matching with variables in CI Lint

Closes #64383

See merge request gitlab-org/gitlab-ce!31719
parents 9a0c1f64 65b20f35
---
title: Fix 500 errors caused by pattern matching with variables in CI Lint
merge_request: 31719
author:
type: fixed
......@@ -11,8 +11,9 @@ module Gitlab
def evaluate(variables = {})
text = @left.evaluate(variables)
regexp = @right.evaluate(variables)
return false unless regexp
regexp.scan(text.to_s).any?
regexp.scan(text.to_s).present?
end
def self.build(_value, behind, ahead)
......
......@@ -11,8 +11,9 @@ module Gitlab
def evaluate(variables = {})
text = @left.evaluate(variables)
regexp = @right.evaluate(variables)
return true unless regexp
regexp.scan(text.to_s).none?
regexp.scan(text.to_s).empty?
end
def self.build(_value, behind, ahead)
......
......@@ -69,6 +69,34 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do
it { is_expected.to eq(false) }
end
context 'when right is nil' do
let(:left_value) { 'my-awesome-string' }
let(:right_value) { nil }
it { is_expected.to eq(false) }
end
context 'when left and right are nil' do
let(:left_value) { nil }
let(:right_value) { nil }
it { is_expected.to eq(false) }
end
context 'when left is an empty string' do
let(:left_value) { '' }
let(:right_value) { Gitlab::UntrustedRegexp.new('pattern') }
it { is_expected.to eq(false) }
end
context 'when left and right are empty strings' do
let(:left_value) { '' }
let(:right_value) { Gitlab::UntrustedRegexp.new('') }
it { is_expected.to eq(true) }
end
context 'when left is a multiline string and matches right' do
let(:left_value) do
<<~TEXT
......
......@@ -69,6 +69,34 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::NotMatches do
it { is_expected.to eq(true) }
end
context 'when right is nil' do
let(:left_value) { 'my-awesome-string' }
let(:right_value) { nil }
it { is_expected.to eq(true) }
end
context 'when left and right are nil' do
let(:left_value) { nil }
let(:right_value) { nil }
it { is_expected.to eq(true) }
end
context 'when left is an empty string' do
let(:left_value) { '' }
let(:right_value) { Gitlab::UntrustedRegexp.new('pattern') }
it { is_expected.to eq(true) }
end
context 'when left and right are empty strings' do
let(:left_value) { '' }
let(:right_value) { Gitlab::UntrustedRegexp.new('') }
it { is_expected.to eq(false) }
end
context 'when left is a multiline string and matches right' do
let(:left_value) do
<<~TEXT
......
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