fix: Allow for underscores in urls

Signed-off-by: phinze <paul.t.hinze@gmail.com>
This commit is contained in:
Adam Stankiewicz 2013-09-22 00:07:19 +02:00 committed by phinze
parent 18aafbc840
commit 590a7bb572
5 changed files with 44 additions and 2 deletions

View file

@ -1,5 +1,5 @@
class Qqbrowser < Cask
url 'http://url.cn/0Q7Ev1' # Refer to #933 regarding usage of shortener
url 'http://dl_dir.qq.com/invc/tt/QQBrowser_1.5.0.2311.dmg'
homepage 'http://browser.qq.com/mac/'
version '1.5.0.2311'
sha1 '0b390037a045e0ea6b0105d2ace1c40f854106ac'

View file

@ -20,6 +20,7 @@ require 'cask/locations'
require 'cask/pkg'
require 'cask/scopes'
require 'cask/system_command'
require 'cask/underscore_supporting_uri'
require 'plist/parser'

View file

@ -24,7 +24,7 @@ module Cask::DSL
end
def url(url=nil)
@url ||= (url && URI.parse(url))
@url ||= Cask::UnderscoreSupportingURI.parse(url)
end
def version(version=nil)

View file

@ -0,0 +1,25 @@
module Cask::UnderscoreSupportingURI
def self.parse(maybe_uri)
return nil if maybe_uri.nil?
URI.parse(maybe_uri)
rescue URI::InvalidURIError
scheme, host, path = simple_parse(maybe_uri)
if host =~ /\_/
URI.parse(without_host_underscores(scheme, host, path)).tap { |uri|
uri.instance_variable_set('@host', host)
}
else
raise
end
end
def self.simple_parse(maybe_uri)
scheme, host_and_path = maybe_uri.split('://')
host, path = host_and_path.split('/', 2)
[scheme, host, path]
end
def self.without_host_underscores(scheme, host, path)
["#{scheme}:/", host.gsub(/\_/, '-'), path].join('/')
end
end

View file

@ -0,0 +1,16 @@
require 'test_helper'
describe Cask::UnderscoreSupportingURI do
describe 'parse' do
it 'works like normal on normal URLs' do
uri = Cask::UnderscoreSupportingURI.parse('http://example.com/TestCask.dmg')
uri.must_equal URI('http://example.com/TestCask.dmg')
end
it 'works just fine on URIs with underscores' do
uri = Cask::UnderscoreSupportingURI.parse('http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg')
uri.host.must_include '_'
uri.to_s.must_equal 'http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg'
end
end
end