Skip to content

Commit

Permalink
Fix #4908 - Do not keep remote file names, generate random (#4934)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Sep 14, 2017
1 parent a4c5001 commit 04046a4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/concerns/remotable.rb
Expand Up @@ -27,9 +27,11 @@ module Remotable

matches = response.headers['content-disposition']&.match(/filename="([^"]*)"/)
filename = matches.nil? ? parsed_url.path.split('/').last : matches[1]
basename = SecureRandom.hex(8)
extname = File.extname(filename)

send("#{attachment_name}=", StringIO.new(response.to_s))
send("#{attachment_name}_file_name=", filename)
send("#{attachment_name}_file_name=", basename + extname)

self[attribute_name] = url if has_attribute?(attribute_name)
rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError, Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError => e
Expand Down

0 comments on commit 04046a4

Please sign in to comment.