Commit e27dc776 authored by Nick Thomas's avatar Nick Thomas

Fix problems with Gitlab::UrlSanitizer

parent 6e31e1b8
...@@ -49,20 +49,20 @@ module Gitlab ...@@ -49,20 +49,20 @@ module Gitlab
private private
def parse_url(url) def parse_url(url)
url = url.strip url = url.to_s.strip
match = url.match(%r{\A(?:ssh|http(?:s?))\://(?:(.+)(?:@))?(.+)}) match = url.match(%r{\A(?:git|ssh|http(?:s?))\://(?:(.+)(?:@))?(.+)})
raw_credentials = match[1] if match raw_credentials = match[1] if match
if raw_credentials.present? if raw_credentials.present?
url.sub!("#{raw_credentials}@", '') url.sub!("#{raw_credentials}@", '')
user, password = raw_credentials.split(':') user, password = raw_credentials.split(':')
@credentials ||= { user: user, password: password } @credentials ||= { user: user.presence, password: password.presence }
end end
url = Addressable::URI.parse(url) url = Addressable::URI.parse(url)
url.user = user url.password = password if password.present?
url.password = password url.user = user if user.present?
url url
end end
...@@ -70,8 +70,8 @@ module Gitlab ...@@ -70,8 +70,8 @@ module Gitlab
return @url unless valid_credentials? return @url unless valid_credentials?
@full_url = @url.dup @full_url = @url.dup
@full_url.password = credentials[:password] @full_url.password = credentials[:password] if credentials[:password].present?
@full_url.user = credentials[:user] @full_url.user = credentials[:user] if credentials[:user].present?
@full_url @full_url
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment