From 132cf30aef69747144afd9f0dba2c7c0dc69eeda Mon Sep 17 00:00:00 2001 From: Aubin Lorieux Date: Thu, 26 Mar 2020 14:05:25 +0100 Subject: [PATCH 1/3] Fix kwargs usage for Ruby 2.7 --- lib/carrierwave/sanitized_file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/sanitized_file.rb b/lib/carrierwave/sanitized_file.rb index b5ba07840..567d2207f 100644 --- a/lib/carrierwave/sanitized_file.rb +++ b/lib/carrierwave/sanitized_file.rb @@ -312,7 +312,7 @@ def file=(file) def mkdir!(path, directory_permissions) options = {} options[:mode] = directory_permissions if directory_permissions - FileUtils.mkdir_p(File.dirname(path), options) unless File.exist?(File.dirname(path)) + FileUtils.mkdir_p(File.dirname(path), **options) unless File.exist?(File.dirname(path)) end def chmod!(path, permissions) From f10026b8e0eda7709a164b6f8304a6b71993d0f6 Mon Sep 17 00:00:00 2001 From: Aubin Lorieux Date: Thu, 26 Mar 2020 14:19:29 +0100 Subject: [PATCH 2/3] Use URI::DEFAULT_PARSER.unescape instead of URI.decode for Ruby 2.7 --- lib/carrierwave/uploader/download.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/carrierwave/uploader/download.rb b/lib/carrierwave/uploader/download.rb index 0ae2d50a7..2654dbcc9 100644 --- a/lib/carrierwave/uploader/download.rb +++ b/lib/carrierwave/uploader/download.rb @@ -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) @@ -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 From 60978361dcd872478f650068804c56f0ed193268 Mon Sep 17 00:00:00 2001 From: Aubin Lorieux Date: Thu, 26 Mar 2020 14:26:23 +0100 Subject: [PATCH 3/3] use URI.open instead of Kernel.open for Ruby 2.7 --- lib/carrierwave/uploader/download.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/carrierwave/uploader/download.rb b/lib/carrierwave/uploader/download.rb index 2654dbcc9..14d35ba5b 100644 --- a/lib/carrierwave/uploader/download.rb +++ b/lib/carrierwave/uploader/download.rb @@ -40,7 +40,7 @@ def file headers = @remote_headers. reverse_merge('User-Agent' => "CarrierWave/#{CarrierWave::VERSION}") - @file = Kernel.open(@uri.to_s, headers) + @file = URI.open(@uri.to_s, headers) @file = @file.is_a?(String) ? StringIO.new(@file) : @file end @file