Skip to content

Commit

Permalink
Use URI::DEFAULT_PARSER.unescape instead of URI.decode for Ruby 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
aubinlrx committed Mar 26, 2020
1 parent 132cf30 commit f10026b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/carrierwave/uploader/download.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def filename_from_header
end

def filename_from_uri
URI.decode(File.basename(file.base_uri.path))
URI::DEFAULT_PARSER.unescape(File.basename(file.base_uri.path))
end

def method_missing(*args, &block)
Expand Down Expand Up @@ -92,8 +92,8 @@ def process_uri(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?
encoded_uri = URI::DEFAULT_PARSER.unescape(uri_parts.shift, /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,]/)
encoded_uri << '?' << URI::DEFAULT_PARSER.unescape(uri_parts.join('?')) if uri_parts.any?
URI.parse(encoded_uri) rescue raise CarrierWave::DownloadError, "couldn't parse URL"
end

Expand Down

0 comments on commit f10026b

Please sign in to comment.