diff options
author | James Lopez <james@jameslopez.es> | 2016-06-30 15:30:07 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-06-30 15:30:07 +0300 |
commit | 545b92af067832d560846b7ec7cb26caf3302275 (patch) | |
tree | 115da30db67e88e68d7583be6af7f95869f1c323 /lib/gitlab | |
parent | 5b893d603dd68f263129523f13e8eb68b67fe790 (diff) |
use class method
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/url_sanitizer.rb | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb index 2eb6085a3ca..50febfc18f8 100644 --- a/lib/gitlab/url_sanitizer.rb +++ b/lib/gitlab/url_sanitizer.rb @@ -1,22 +1,23 @@ module Gitlab class UrlSanitizer - attr_reader :valid - alias_method :valid?, :valid - def self.sanitize(content) regexp = URI::Parser.new.make_regexp(['http', 'https', 'ssh', 'git']) content.gsub(regexp) { |url| new(url).masked_url } end + def self.valid?(url) + Addressable::URI.parse(url.strip) + + true + rescue Addressable::URI::InvalidURIError + false + end + def initialize(url, credentials: nil) - @valid = true @url = Addressable::URI.parse(url.strip) @credentials = credentials - rescue Addressable::URI::InvalidURIError - @valid = false - raise end def sanitized_url |