summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Goodman <jgoodman@gitlab.com>2019-07-26 18:36:13 -0400
committerJason Goodman <jgoodman@gitlab.com>2019-07-31 10:58:47 -0400
commit2f5ddd2b622b5e233ead45a38d1416c2d6c05f2a (patch)
tree114078cdec7b238771af05e4eebd9f17ab2d236d
parent2e7f4bbb66b4bae61c9dd09234e8435c91e7e986 (diff)
downloadgitlab-ce-2f5ddd2b622b5e233ead45a38d1416c2d6c05f2a.tar.gz
Remove trailing slash from external_url in Environment#external_url_for
-rw-r--r--app/models/environment.rb2
-rw-r--r--spec/models/environment_spec.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 392481ea0cc..72f695230e1 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -204,7 +204,7 @@ class Environment < ApplicationRecord
public_path = project.public_path_for_source_path(path, commit_sha)
return unless public_path
- [external_url, public_path].join('/')
+ [external_url.delete_suffix('/'), public_path].join('/')
end
def expire_etag_cache
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index ce0681c4331..8e0adcbbf9d 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -804,6 +804,12 @@ describe Environment, :use_clean_rails_memory_store_caching do
it 'returns the full external URL' do
expect(environment.external_url_for(source_path, sha)).to eq('http://example.com/file.html')
end
+
+ it 'returns the proper url when the environment external_url ends in a slash' do
+ environment.external_url = 'http://example.com/sub/'
+
+ expect(environment.external_url_for(source_path, sha)).to eq('http://example.com/sub/file.html')
+ end
end
end