2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SafeUrl
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def safe_url(allowed_usernames: [])
|
2020-01-01 13:55:28 +05:30
|
|
|
return if url.nil?
|
|
|
|
|
|
|
|
uri = URI.parse(url)
|
|
|
|
uri.password = '*****' if uri.password
|
2021-04-29 21:17:54 +05:30
|
|
|
uri.user = '*****' if uri.user && allowed_usernames.exclude?(uri.user)
|
2020-01-01 13:55:28 +05:30
|
|
|
uri.to_s
|
|
|
|
rescue URI::Error
|
|
|
|
end
|
|
|
|
end
|