Commit 3bff85a4 authored by Stan Hu's avatar Stan Hu

Fix the writing of invalid environment refs

Environment names that contained a space would cause an error
in GitLab 10.1 because a new guard clause was introduced in
Repository#write_ref to prevent such references from
existing. Use the slug instead to ensure that the name
is valid.

Closes #39182
parent 40ded704
......@@ -110,7 +110,7 @@ class Environment < ActiveRecord::Base
end
def ref_path
"refs/#{Repository::REF_ENVIRONMENTS}/#{Shellwords.shellescape(name)}"
"refs/#{Repository::REF_ENVIRONMENTS}/#{generate_slug}"
end
def formatted_external_url
......
---
title: Fix the writing of invalid environment refs
merge_request:
author:
type: fixed
......@@ -575,6 +575,16 @@ describe Environment do
end
end
describe '#ref_path' do
subject(:environment) do
create(:environment, name: 'staging / review-1')
end
it 'returns a path that uses the slug and does not have spaces' do
expect(environment.ref_path).to start_with('refs/environments/staging-review-1-')
end
end
describe '#external_url_for' do
let(:source_path) { 'source/file.html' }
let(:sha) { RepoHelpers.sample_commit.id }
......
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