diff --git a/Casks/qqbrowser.rb b/Casks/qqbrowser.rb index 817da917b..f84fb0045 100644 --- a/Casks/qqbrowser.rb +++ b/Casks/qqbrowser.rb @@ -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' diff --git a/lib/cask.rb b/lib/cask.rb index bddfd055d..7f5bb75fa 100644 --- a/lib/cask.rb +++ b/lib/cask.rb @@ -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' diff --git a/lib/cask/dsl.rb b/lib/cask/dsl.rb index 3aa8ad89e..0197435c2 100644 --- a/lib/cask/dsl.rb +++ b/lib/cask/dsl.rb @@ -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) diff --git a/lib/cask/underscore_supporting_uri.rb b/lib/cask/underscore_supporting_uri.rb new file mode 100644 index 000000000..dac5c2850 --- /dev/null +++ b/lib/cask/underscore_supporting_uri.rb @@ -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 diff --git a/test/cask/underscore_supporting_uri_test.rb b/test/cask/underscore_supporting_uri_test.rb new file mode 100644 index 000000000..13bb79ff9 --- /dev/null +++ b/test/cask/underscore_supporting_uri_test.rb @@ -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