Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Handle already encoded URLs
Browse files Browse the repository at this point in the history
Closes #2253
  • Loading branch information
ivanoblomov authored and sidraval committed May 7, 2018
1 parent b4e613b commit bc093cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/paperclip/io_adapters/http_url_proxy_adapter.rb
Expand Up @@ -9,7 +9,8 @@ def self.register
REGEXP = /\Ahttps?:\/\//

def initialize(target, options = {})
super(URI(URI.escape(target)), options)
escaped = URI.escape(target)
super(URI(target == URI.unescape(target) ? escaped : target), options)
end
end
end
25 changes: 21 additions & 4 deletions spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb
Expand Up @@ -107,15 +107,32 @@
end

context "a url with special characters in the filename" do
it "returns a encoded filename" do
before do
Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).
returns(@open_return)
url = "https://github.com/thoughtbot/paperclip-öäü字´½♥زÈ.png"
subject = Paperclip.io_adapters.for(url)
filename = "paperclip-%C3%B6%C3%A4%C3%BC%E5%AD%97%C2%B4%C2%BD%E2%99%A5"\
end

let(:filename) do
"paperclip-%C3%B6%C3%A4%C3%BC%E5%AD%97%C2%B4%C2%BD%E2%99%A5"\
"%C3%98%C2%B2%C3%88.png"
end
let(:url) { "https://github.com/thoughtbot/paperclip-öäü字´½♥زÈ.png" }

subject { Paperclip.io_adapters.for(url) }

it "returns a encoded filename" do
assert_equal filename, subject.original_filename
end

context "when already URI encoded" do
let(:url) do
"https://github.com/thoughtbot/paperclip-%C3%B6%C3%A4%C3%BC%E5%AD%97"\
"%C2%B4%C2%BD%E2%99%A5%C3%98%C2%B2%C3%88.png"
end

it "returns a encoded filename" do
assert_equal filename, subject.original_filename
end
end
end
end

0 comments on commit bc093cf

Please sign in to comment.