debian-mirror-gitlab/app/models/concerns/safe_url.rb
2021-04-29 21:17:54 +05:30

15 lines
327 B
Ruby

# frozen_string_literal: true
module SafeUrl
extend ActiveSupport::Concern
def safe_url(allowed_usernames: [])
return if url.nil?
uri = URI.parse(url)
uri.password = '*****' if uri.password
uri.user = '*****' if uri.user && allowed_usernames.exclude?(uri.user)
uri.to_s
rescue URI::Error
end
end