summaryrefslogtreecommitdiff
path: root/lib/api/helpers
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-05-22 08:54:20 +0000
committerDouwe Maan <douwe@gitlab.com>2018-05-22 08:54:20 +0000
commit0af4c56cff7a78a873f6c82e0942fbb2a394e71c (patch)
treea7d32638bf9ac680c145b9baa705c4a1829af33d /lib/api/helpers
parent735727618565a732a2801ff758495793c8e93eed (diff)
downloadgitlab-ce-0af4c56cff7a78a873f6c82e0942fbb2a394e71c.tar.gz
Fix `expose_url` helper does not include custom base url if it is set
Diffstat (limited to 'lib/api/helpers')
-rw-r--r--lib/api/helpers/related_resources_helpers.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/api/helpers/related_resources_helpers.rb b/lib/api/helpers/related_resources_helpers.rb
index 7f4d6e58b34..a2cbed30229 100644
--- a/lib/api/helpers/related_resources_helpers.rb
+++ b/lib/api/helpers/related_resources_helpers.rb
@@ -13,9 +13,14 @@ module API
def expose_url(path)
url_options = Gitlab::Application.routes.default_url_options
- protocol, host, port = url_options.slice(:protocol, :host, :port).values
+ protocol, host, port, script_name = url_options.values_at(:protocol, :host, :port, :script_name)
- URI::Generic.build(scheme: protocol, host: host, port: port, path: path).to_s
+ # Using a blank component at the beginning of the join we ensure
+ # that the resulted path will start with '/'. If the resulted path
+ # does not start with '/', URI::Generic#build will fail
+ path_with_script_name = File.join('', [script_name, path].select(&:present?))
+
+ URI::Generic.build(scheme: protocol, host: host, port: port, path: path_with_script_name).to_s
end
private