diff options
Diffstat (limited to 'app/models/concerns/safe_url.rb')
-rw-r--r-- | app/models/concerns/safe_url.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/concerns/safe_url.rb b/app/models/concerns/safe_url.rb new file mode 100644 index 00000000000..febca7d241f --- /dev/null +++ b/app/models/concerns/safe_url.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module SafeUrl + extend ActiveSupport::Concern + + def safe_url(usernames_whitelist: []) + return if url.nil? + + uri = URI.parse(url) + uri.password = '*****' if uri.password + uri.user = '*****' if uri.user && !usernames_whitelist.include?(uri.user) + uri.to_s + rescue URI::Error + end +end |