1# frozen_string_literal: true
2
3module SafeUrl
4  extend ActiveSupport::Concern
5
6  def safe_url(allowed_usernames: [])
7    return if url.nil?
8
9    uri = URI.parse(url)
10    uri.password = '*****' if uri.password
11    uri.user = '*****' if uri.user && allowed_usernames.exclude?(uri.user)
12    uri.to_s
13  rescue URI::Error
14  end
15end
16