Commit 4c12f02f authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

Checks for data type before expansion

Expand variable only if its of the type String
parent 9ffb0985
......@@ -105,8 +105,19 @@ module Gitlab
if data.is_a?(String)
expand(data)
else
data.transform_values do |values|
values.is_a?(Array) ? values.map { |value| expand(value) } : expand(values)
transform(data)
end
end
def transform(data)
data.transform_values do |values|
case values
when Array
values.map { |value| expand(value.to_s) }
when String
expand(values)
else
values
end
end
end
......
......@@ -322,6 +322,19 @@ RSpec.describe Gitlab::Ci::Config::External::Mapper do
end
end
context 'when include variable has an unsupported type for variable expansion' do
let(:values) do
{ include: { project: project.id, file: local_file },
image: 'ruby:2.7' }
end
it 'does not invoke expansion for the variable', :aggregate_failures do
expect(ExpandVariables).not_to receive(:expand).with(project.id, context_params[:variables])
expect { subject }.to raise_error(described_class::AmbigiousSpecificationError)
end
end
context 'when feature flag is turned off' do
let(:values) do
{ include: full_local_file_path }
......
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