url_generator_extensions.rb 489 B

1234567891011121314151617
  1. # frozen_string_literal: true
  2. module Paperclip
  3. module UrlGeneratorExtensions
  4. # Monkey-patch Paperclip to use Addressable::URI's normalization instead
  5. # of the long-deprecated URI.esacpe
  6. def escape_url(url)
  7. if url.respond_to?(:escape)
  8. url.escape
  9. else
  10. Addressable::URI.parse(url).normalize.to_str.gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" }
  11. end
  12. end
  13. end
  14. end
  15. Paperclip::UrlGenerator.prepend(Paperclip::UrlGeneratorExtensions)