debian-mirror-gitlab/app/models/concerns/safe_url.rb

16 lines
327 B
Ruby
Raw Normal View History

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