Commit 545b92af authored by James Lopez's avatar James Lopez

use class method

parent 5b893d60
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
......
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