summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-31 21:14:36 -0700
committerStan Hu <stanhu@gmail.com>2018-07-31 21:14:36 -0700
commitd2fd6d23513b18b2fd6fe93fe76e5ea4c97120b3 (patch)
treeef35db5cc12ac84a3446770ea2376492c1eca7a5 /lib
parent7704404335814b39922d32eacf6b6f0961b9820f (diff)
downloadgitlab-ce-d2fd6d23513b18b2fd6fe93fe76e5ea4c97120b3.tar.gz
Deal with subpaths and trailing slashes properly
Diffstat (limited to 'lib')
-rw-r--r--lib/bitbucket_server/connection.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb
index a43b4364cab..a3150cc38d5 100644
--- a/lib/bitbucket_server/connection.rb
+++ b/lib/bitbucket_server/connection.rb
@@ -5,6 +5,7 @@ module BitbucketServer
include ActionView::Helpers::SanitizeHelper
DEFAULT_API_VERSION = '1.0'
+ SEPARATOR = '/'
attr_reader :api_version, :base_uri, :username, :token
@@ -87,19 +88,35 @@ module BitbucketServer
def build_url(path)
return path if path.starts_with?(root_url)
- URI.join(root_url, path).to_s
+ url_join_paths(root_url, path)
end
def root_url
- URI.join(base_uri, "/rest/api/#{api_version}").to_s
+ url_join_paths(base_uri, "/rest/api/#{api_version}")
end
def delete_url(resource, path)
if resource == :branches
- URI.join(base_uri, "/rest/branch-utils/#{api_version}#{path}").to_s
+ url_join_paths(base_uri, "/rest/branch-utils/#{api_version}#{path}")
else
build_url(path)
end
end
+
+ # URI.join is stupid in that slashes are important:
+ #
+ # # URI.join('http://example.com/subpath', 'hello')
+ # => http://example.com/hello
+ #
+ # We really want http://example.com/subpath/hello
+ #
+ def url_join_paths(*paths)
+ paths.map { |path| strip_slashes(path) }.join(SEPARATOR)
+ end
+
+ def strip_slashes(path)
+ path = path[1..-1] if path.starts_with?(SEPARATOR)
+ path.chomp(SEPARATOR)
+ end
end
end