2019-12-17 10:08:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SafeUrl
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2021-03-22 08:09:02 -04:00
|
|
|
def safe_url(allowed_usernames: [])
|
2019-12-17 10:08:15 -05:00
|
|
|
return if url.nil?
|
|
|
|
|
|
|
|
uri = URI.parse(url)
|
|
|
|
uri.password = '*****' if uri.password
|
2021-03-22 08:09:02 -04:00
|
|
|
uri.user = '*****' if uri.user && allowed_usernames.exclude?(uri.user)
|
2019-12-17 10:08:15 -05:00
|
|
|
uri.to_s
|
|
|
|
rescue URI::Error
|
|
|
|
end
|
|
|
|
end
|