From 0c8945e5ff9e75dd322ee2b2c4ea9cc1dc728911 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 26 Mar 2020 01:56:41 +0100 Subject: Change `tootctl media remove-orphans` to work for all classes (#13316) Change `tootctl media lookup` to not use an interactive prompt --- lib/paperclip/attachment_extensions.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/paperclip') diff --git a/lib/paperclip/attachment_extensions.rb b/lib/paperclip/attachment_extensions.rb index 3b308af5f..d9ec0159a 100644 --- a/lib/paperclip/attachment_extensions.rb +++ b/lib/paperclip/attachment_extensions.rb @@ -24,6 +24,19 @@ module Paperclip flush_deletes end end + + def variant?(other_filename) + return true if original_filename == other_filename + return false if original_filename.nil? + + formats = styles.values.map(&:format).compact + + return false if formats.empty? + + other_extension = File.extname(other_filename) + + formats.include?(other_extension.delete('.')) && File.basename(other_filename, other_extension) == File.basename(original_filename, File.extname(original_filename)) + end end end -- cgit From 6c79b7237e31eb510af7df3f4f2cb133dea39845 Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 26 Mar 2020 15:09:16 +0100 Subject: Fix Paperclip using deprecated URI.escape function (#13320) Monkey-patch Paperclip to perform URL escaping in a slightly more appropriate way, and get rid of runtime deprecation warnings. --- config/application.rb | 1 + lib/paperclip/url_generator_extensions.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 lib/paperclip/url_generator_extensions.rb (limited to 'lib/paperclip') diff --git a/config/application.rb b/config/application.rb index cd599eefc..4c34efa15 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,6 +7,7 @@ require 'rails/all' Bundler.require(*Rails.groups) require_relative '../app/lib/exceptions' +require_relative '../lib/paperclip/url_generator_extensions' require_relative '../lib/paperclip/attachment_extensions' require_relative '../lib/paperclip/lazy_thumbnail' require_relative '../lib/paperclip/gif_transcoder' diff --git a/lib/paperclip/url_generator_extensions.rb b/lib/paperclip/url_generator_extensions.rb new file mode 100644 index 000000000..1079efdbc --- /dev/null +++ b/lib/paperclip/url_generator_extensions.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Paperclip + module UrlGeneratorExtensions + # Monkey-patch Paperclip to use Addressable::URI's normalization instead + # of the long-deprecated URI.esacpe + def escape_url(url) + if url.respond_to?(:escape) + url.escape + else + Addressable::URI.parse(url).normalize.to_str.gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" } + end + end + end +end + +Paperclip::UrlGenerator.prepend(Paperclip::UrlGeneratorExtensions) -- cgit