summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2017-09-06 12:29:14 +0100
committerNick Thomas <nick@gitlab.com>2017-09-06 15:29:13 +0100
commit759f34bd0a250cb2cdf1b718837b56bb28fa1939 (patch)
tree50a007c6d51ef6fbd9a6cea33c5bccf7c23d6a22
parent5dd06f69c3ad316518fe5374010081d89e5febe7 (diff)
downloadgitlab-ce-759f34bd0a250cb2cdf1b718837b56bb28fa1939.tar.gz
Backport EE fixes to Gitlab::UrlSanitizer to CE
-rw-r--r--lib/gitlab/url_sanitizer.rb12
-rw-r--r--spec/lib/gitlab/url_sanitizer_spec.rb1
2 files changed, 7 insertions, 6 deletions
diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb
index c81dc7e30d0..9c26490f40f 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)
@@ -29,13 +29,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 +47,8 @@ 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].presence
+ @full_url.password = credentials[:password].presence
@full_url
end
diff --git a/spec/lib/gitlab/url_sanitizer_spec.rb b/spec/lib/gitlab/url_sanitizer_spec.rb
index 308b1a128be..c1dc39b38de 100644
--- a/spec/lib/gitlab/url_sanitizer_spec.rb
+++ b/spec/lib/gitlab/url_sanitizer_spec.rb
@@ -57,6 +57,7 @@ describe Gitlab::UrlSanitizer do
describe '.valid?' do
it 'validates url strings' do
expect(described_class.valid?(nil)).to be(false)
+ expect(described_class.valid?('')).to be(false)
expect(described_class.valid?('valid@project:url.git')).to be(true)
expect(described_class.valid?('123://invalid:url')).to be(false)
end