Skip to content

Commit e03ae73

Browse files
committed
Merge pull request discourse#1653 from ScotterC/uri-addressable
URI adapter should use Addressable
2 parents 16267e4 + 32e4146 commit e03ae73

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

app/services/uri_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ class UriAdapter
66
def initialize(target)
77
raise Discourse::InvalidParameters unless target =~ /^https?:\/\//
88

9-
@target = URI(target)
9+
@target = Addressable::URI.parse(target)
1010
@original_filename = ::File.basename(@target.path)
1111
@content = download_content
1212
@tempfile = TempfileFactory.new.generate(@original_filename)
1313
end
1414

1515
def download_content
16-
open(target)
16+
open(target.normalize)
1717
end
1818

1919
def copy_to_tempfile(src)

spec/services/uri_adapter_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
describe "#initialize" do
1515

1616
it "has a target" do
17-
subject.target.should be_instance_of(URI::HTTP)
17+
subject.target.should be_instance_of(Addressable::URI)
1818
end
1919

2020
it "has content" do
@@ -29,6 +29,27 @@
2929
subject.tempfile.should be_instance_of Tempfile
3030
end
3131

32+
describe "it handles ugly targets" do
33+
let(:ugly_target) { "http://cdn.discourse.org/assets/logo with spaces.png" }
34+
subject { UriAdapter.new(ugly_target) }
35+
36+
it "handles targets" do
37+
subject.target.should be_instance_of(Addressable::URI)
38+
end
39+
40+
it "has content" do
41+
subject.content.should == response
42+
end
43+
44+
it "has an original_filename" do
45+
subject.original_filename.should == "logo with spaces.png"
46+
end
47+
48+
it "has a tempfile" do
49+
subject.tempfile.should be_instance_of Tempfile
50+
end
51+
end
52+
3253
end
3354

3455
describe "#copy_to_tempfile" do

0 commit comments

Comments
 (0)