Commit 759f34bd authored by Nick Thomas's avatar Nick Thomas

Backport EE fixes to Gitlab::UrlSanitizer to CE

parent 5dd06f69
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
end end
def self.valid?(url) def self.valid?(url)
return false unless url return false unless url.present?
Addressable::URI.parse(url.strip) Addressable::URI.parse(url.strip)
...@@ -29,13 +29,13 @@ module Gitlab ...@@ -29,13 +29,13 @@ module Gitlab
def masked_url def masked_url
url = @url.dup url = @url.dup
url.password = "*****" unless url.password.nil? url.password = "*****" if url.password.present?
url.user = "*****" unless url.user.nil? url.user = "*****" if url.user.present?
url.to_s url.to_s
end end
def credentials def credentials
@credentials ||= { user: @url.user, password: @url.password } @credentials ||= { user: @url.user.presence, password: @url.password.presence }
end end
def full_url def full_url
...@@ -47,8 +47,8 @@ module Gitlab ...@@ -47,8 +47,8 @@ module Gitlab
def generate_full_url def generate_full_url
return @url unless valid_credentials? return @url unless valid_credentials?
@full_url = @url.dup @full_url = @url.dup
@full_url.user = credentials[:user] @full_url.user = credentials[:user].presence
@full_url.password = credentials[:password] @full_url.password = credentials[:password].presence
@full_url @full_url
end end
......
...@@ -57,6 +57,7 @@ describe Gitlab::UrlSanitizer do ...@@ -57,6 +57,7 @@ describe Gitlab::UrlSanitizer do
describe '.valid?' do describe '.valid?' do
it 'validates url strings' do it 'validates url strings' do
expect(described_class.valid?(nil)).to be(false) 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?('valid@project:url.git')).to be(true)
expect(described_class.valid?('123://invalid:url')).to be(false) expect(described_class.valid?('123://invalid:url')).to be(false)
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