lib/carrierwave/uploader/download.rb in carrierwave-0.8.0 vs lib/carrierwave/uploader/download.rb in carrierwave-0.9.0
- old
+ new
@@ -15,10 +15,14 @@
def initialize(uri)
@uri = uri
end
def original_filename
+ if file.meta.include? 'content-disposition'
+ match = file.meta['content-disposition'].match(/filename=(\"?)(.+)\1/)
+ return match[2] unless match.nil?
+ end
File.basename(file.base_uri.path)
end
def respond_to?(*args)
super or file.respond_to?(*args)
@@ -68,10 +72,16 @@
# === Parameters
#
# [url (String)] The URL where the remote file is stored
#
def process_uri(uri)
- URI.parse(URI.escape(URI.unescape(uri)))
+ URI.parse(uri)
+ rescue URI::InvalidURIError
+ uri_parts = uri.split('?')
+ # regexp from Ruby's URI::Parser#regexp[:UNSAFE], with [] specifically removed
+ encoded_uri = URI.encode(uri_parts.shift, /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,]/)
+ encoded_uri << '?' << URI.encode(uri_parts.join('?')) if uri_parts.any?
+ URI.parse(encoded_uri) rescue raise CarrierWave::DownloadError, "couldn't parse URL"
end
end # Download
end # Uploader
end # CarrierWave