diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2018-11-06 21:54:55 -0200 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-11-06 21:32:01 -0800 |
commit | 5c519d1194d6d3ad4b61389b8143baac9ae598ad (patch) | |
tree | b703ca1e1d51acdc979d7455f40fe80162409741 /lib | |
parent | cf8fe12b7b3a24082db47f71c80b01e62e391f32 (diff) | |
download | gitlab-ce-5c519d1194d6d3ad4b61389b8143baac9ae598ad.tar.gz |
Add a helper method to append path to a base URL4459-redirect-users-back-to-secondary-after-logout-login
In Ruby 2.4, `URI.join("http://test//", "a").to_s` will
remove the double slash, however it's not the case in
Ruby 2.5. Using chomp should work better for the intention,
as we're not trying to allow things like ../ or / paths
resolution.
This helper method append path to host, making sure
there's one single slash as path separator.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/utils.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/gitlab/utils.rb b/lib/gitlab/utils.rb index 2c92458f777..9e59137a2c0 100644 --- a/lib/gitlab/utils.rb +++ b/lib/gitlab/utils.rb @@ -16,6 +16,11 @@ module Gitlab str.force_encoding(Encoding::UTF_8) end + # Append path to host, making sure there's one single / in between + def append_path(host, path) + "#{host.to_s.sub(%r{\/+$}, '')}/#{path.to_s.sub(%r{^\/+}, '')}" + end + # A slugified version of the string, suitable for inclusion in URLs and # domain names. Rules: # |