BigW Consortium Gitlab

Commit 759f34bd by Nick Thomas

Backport EE fixes to Gitlab::UrlSanitizer to CE

parent 5dd06f69
......@@ -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
......
......@@ -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
......
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