summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-07-11 09:01:09 +0200
committerJames Lopez <james@jameslopez.es>2016-07-11 09:01:09 +0200
commit99f7b6d24684dcb9dbff79c8ff08f8c7580dcafe (patch)
tree894696ac2522db2768fa6d26744312ca7a27e7d3
parent94e9d571c03932a0d71a5f10720d95ef014164c2 (diff)
downloadgitlab-ce-99f7b6d24684dcb9dbff79c8ff08f8c7580dcafe.tar.gz
spec and fix for sanitize method
-rw-r--r--lib/gitlab/url_sanitizer.rb2
-rw-r--r--spec/lib/gitlab/url_sanitizer_spec.rb6
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb
index 86ed18fb50d..19dad699edf 100644
--- a/lib/gitlab/url_sanitizer.rb
+++ b/lib/gitlab/url_sanitizer.rb
@@ -4,6 +4,8 @@ module Gitlab
regexp = URI::Parser.new.make_regexp(['http', 'https', 'ssh', 'git'])
content.gsub(regexp) { |url| new(url).masked_url }
+ rescue Addressable::URI::InvalidURIError
+ content.gsub(regexp, '')
end
def self.valid?(url)
diff --git a/spec/lib/gitlab/url_sanitizer_spec.rb b/spec/lib/gitlab/url_sanitizer_spec.rb
index 59024d3290b..2cb74629da8 100644
--- a/spec/lib/gitlab/url_sanitizer_spec.rb
+++ b/spec/lib/gitlab/url_sanitizer_spec.rb
@@ -45,6 +45,12 @@ describe Gitlab::UrlSanitizer, lib: true do
expect(filtered_content).to include("user@server:project.git")
end
+
+ it 'returns an empty string for invalid URLs' do
+ filtered_content = sanitize_url('ssh://')
+
+ expect(filtered_content).to include("repository '' not found")
+ end
end
describe '#sanitized_url' do