diff options
author | ThibG <thib@sitedethib.com> | 2020-03-28 15:19:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-28 15:19:05 +0100 |
commit | a192b193bdf7013df09c6cd63916274cd9d47cf7 (patch) | |
tree | 413de2a72a6f3a126e19e12178524ca33c27e436 /lib/paperclip | |
parent | 02f1c04fabab221130de8dfb5611be81825b193b (diff) | |
parent | d98fabf2ee44c2c25775066abda46552ab05993e (diff) |
Merge pull request #1308 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib/paperclip')
-rw-r--r-- | lib/paperclip/attachment_extensions.rb | 13 | ||||
-rw-r--r-- | lib/paperclip/url_generator_extensions.rb | 17 |
2 files changed, 30 insertions, 0 deletions
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 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) |