Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library incorrectly removes the hostname and protocol from Web Proxy paths #8

Merged
merged 1 commit into from
May 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ Rake::TestTask.new(:test) do |t|
t.pattern = 'test/**/*_test.rb'
end
task :default => :test

task :console do
require 'irb'
require 'irb/completion'
require 'imgix'
ARGV.clear
IRB.start
end
1 change: 1 addition & 0 deletions lib/imgix/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def initialize(prefix, token, path = '/')
@path = path
@options = {}

@path = CGI.escape(@path) if /^https?/ =~ @path
@path = "/#{@path}" if @path[0] != '/'
end

Expand Down
14 changes: 12 additions & 2 deletions test/units/domains_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_cycling_choosing_domain_in_order

path = client.path('/bridge.png')
assert_equal 'http://demos-1.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url

end

def test_strips_out_protocol
Expand All @@ -47,7 +46,18 @@ def test_strips_out_protocol

path = client.path('/bridge.png')
assert_equal 'http://demos-1.imgix.net/bridge.png?&s=13e68f249172e5f790344e85e7cdb14b', path.to_url

end

def test_with_full_paths
client = Imgix::Client.new(:hosts => [
"demos-1.imgix.net",
"demos-2.imgix.net",
"demos-3.imgix.net",
],
:token => '10adc394',
:shard_strategy => :cycle)

path = 'https://google.com/cats.gif'
assert_equal "http://demos-1.imgix.net/#{CGI.escape(path)}?&s=4c3ff935011f0d2251800e6a2bb68ee5", client.path(path).to_url
end
end
13 changes: 12 additions & 1 deletion test/units/path_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ def test_token_is_optional
assert_equal url, path.to_url
end

private
def test_full_url
path = 'https://google.com/cats.gif'

assert_equal "http://demo.imgix.net/#{CGI.escape(path)}?&s=4c3ff935011f0d2251800e6a2bb68ee5", client.path(path).to_url
end

def test_full_url_with_a_space
path = 'https://my-demo-site.com/files/133467012/avatar icon.png'
assert_equal "http://demo.imgix.net/#{CGI.escape(path)}?&s=8943817bed50811f6ceedd8f4b84169d", client.path(path).to_url
end

private

def client
@client ||= Imgix::Client.new(:host => 'demo.imgix.net', :token => '10adc394')
Expand Down