Commit bc093cf6 by Roderick Monje Committed by Sid Raval

Handle already encoded URLs

Closes https://github.com/thoughtbot/paperclip/issues/2253
parent b4e613b2
...@@ -9,7 +9,8 @@ module Paperclip ...@@ -9,7 +9,8 @@ module Paperclip
REGEXP = /\Ahttps?:\/\// REGEXP = /\Ahttps?:\/\//
def initialize(target, options = {}) 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 end
end end
...@@ -107,15 +107,32 @@ describe Paperclip::HttpUrlProxyAdapter do ...@@ -107,15 +107,32 @@ describe Paperclip::HttpUrlProxyAdapter do
end end
context "a url with special characters in the filename" do 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). Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).
returns(@open_return) returns(@open_return)
url = "https://github.com/thoughtbot/paperclip-öäü字´½♥زÈ.png" end
subject = Paperclip.io_adapters.for(url)
filename = "paperclip-%C3%B6%C3%A4%C3%BC%E5%AD%97%C2%B4%C2%BD%E2%99%A5"\ 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" "%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 assert_equal filename, subject.original_filename
end end
end end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment