diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-09-06 16:15:02 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-09-06 16:15:02 +0000 |
commit | 04f887420999a14c6188db93f7c10add02f514f4 (patch) | |
tree | 8fd7d1df20d5a28be20522b67d8ee4cdcfb0a2bc /lib | |
parent | 29a34b3c283634192d6bf0e4200296569deb18ba (diff) | |
parent | c8bdb20228b34130c7f0525ad92140702dce1e20 (diff) | |
download | gitlab-ce-04f887420999a14c6188db93f7c10add02f514f4.tar.gz |
Merge branch 'url-sanitizer-fixes' into 'master'
Fix problems sanitizing URLs with empty passwords
Closes gitlab-ee#3352
See merge request !14083
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/url_sanitizer.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb index c81dc7e30d0..703adae12cb 100644 --- a/lib/gitlab/url_sanitizer.rb +++ b/lib/gitlab/url_sanitizer.rb @@ -9,7 +9,7 @@ module Gitlab end def self.valid?(url) - return false unless url + return false unless url.present? Addressable::URI.parse(url.strip) @@ -19,7 +19,12 @@ module Gitlab end def initialize(url, credentials: nil) - @url = Addressable::URI.parse(url.strip) + @url = Addressable::URI.parse(url.to_s.strip) + + %i[user password].each do |symbol| + credentials[symbol] = credentials[symbol].presence if credentials&.key?(symbol) + end + @credentials = credentials end @@ -29,13 +34,13 @@ module Gitlab def masked_url url = @url.dup - url.password = "*****" unless url.password.nil? - url.user = "*****" unless url.user.nil? + url.password = "*****" if url.password.present? + url.user = "*****" if url.user.present? url.to_s end def credentials - @credentials ||= { user: @url.user, password: @url.password } + @credentials ||= { user: @url.user.presence, password: @url.password.presence } end def full_url @@ -47,8 +52,10 @@ module Gitlab def generate_full_url return @url unless valid_credentials? @full_url = @url.dup - @full_url.user = credentials[:user] + @full_url.password = credentials[:password] + @full_url.user = credentials[:user] + @full_url end |