diff options
author | Stan Hu <stanhu@gmail.com> | 2017-10-23 03:57:51 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2017-10-23 04:15:26 +0300 |
commit | 3bff85a4f659438edbbc486a0b3c32ff589ab299 (patch) | |
tree | 8132af0cb2f83ffea9b37a8d841cc1e35ae789b7 | |
parent | 40ded704cc9b535bee9afd45512d52173c3fc0e7 (diff) | |
download | gitlab-ce-sh-fix-environment-write-ref.tar.gz |
Fix the writing of invalid environment refssh-fix-environment-write-ref
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
-rw-r--r-- | app/models/environment.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-environment-write-ref.yml | 5 | ||||
-rw-r--r-- | spec/models/environment_spec.rb | 10 |
3 files changed, 16 insertions, 1 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index b6868ccbe8f..e613d21add6 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -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 diff --git a/changelogs/unreleased/sh-fix-environment-write-ref.yml b/changelogs/unreleased/sh-fix-environment-write-ref.yml new file mode 100644 index 00000000000..8f291843ebe --- /dev/null +++ b/changelogs/unreleased/sh-fix-environment-write-ref.yml @@ -0,0 +1,5 @@ +--- +title: Fix the writing of invalid environment refs +merge_request: +author: +type: fixed diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 25e5d155894..e1be23541e8 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -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 } |