From a92b6318eb9895ed962612c26abbf0c3f25ce09a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 3 Oct 2017 08:29:20 +0200 Subject: [PATCH] Remove `UnderscoreSupportingURI`. --- Library/Homebrew/cask/lib/hbc.rb | 1 - Library/Homebrew/cask/lib/hbc/dsl/appcast.rb | 2 +- Library/Homebrew/cask/lib/hbc/dsl/gpg.rb | 6 ++-- .../cask/lib/hbc/underscore_supporting_uri.rb | 28 ------------------- Library/Homebrew/cask/lib/hbc/url.rb | 2 +- .../Homebrew/test/cask/dsl/appcast_spec.rb | 2 +- .../cask/underscore_supporting_uri_spec.rb | 14 ---------- 7 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb delete mode 100644 Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 780acedf57..01a0850192 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -25,7 +25,6 @@ require "hbc/scopes" require "hbc/staged" require "hbc/system_command" require "hbc/topological_hash" -require "hbc/underscore_supporting_uri" require "hbc/url" require "hbc/utils" require "hbc/verify" diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb index fc7e83a20d..f984ac088c 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb @@ -7,7 +7,7 @@ module Hbc def initialize(uri, parameters = {}) @parameters = parameters - @uri = UnderscoreSupportingURI.parse(uri) + @uri = URI(uri) @checkpoint = @parameters[:checkpoint] end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb b/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb index b49ebb97cd..99b39d43fd 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb @@ -14,11 +14,11 @@ module Hbc def initialize(signature, parameters = {}) @parameters = parameters - @signature = UnderscoreSupportingURI.parse(signature) + @signature = URI(signature) parameters.each do |hkey, hvalue| raise "invalid 'gpg' parameter: '#{hkey.inspect}'" unless VALID_PARAMETERS.include?(hkey) writer_method = "#{hkey}=".to_sym - hvalue = UnderscoreSupportingURI.parse(hvalue) if hkey == :key_url + hvalue = URI(hvalue) if hkey == :key_url valid_id?(hvalue) if hkey == :key_id send(writer_method, hvalue) end @@ -35,7 +35,7 @@ module Hbc end def to_yaml - # bug, :key_url value is not represented as an instance of Hbc::UnderscoreSupportingURI + # bug, :key_url value is not represented as an instance of URI [@signature, @parameters].to_yaml end diff --git a/Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb b/Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb deleted file mode 100644 index 8f8f66f43e..0000000000 --- a/Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb +++ /dev/null @@ -1,28 +0,0 @@ -require "uri" - -module Hbc - module UnderscoreSupportingURI - def self.parse(maybe_uri) - return nil if maybe_uri.nil? - URI.parse(maybe_uri) - rescue URI::InvalidURIError => e - scheme, host, path = simple_parse(maybe_uri) - raise e unless path && host.include?("_") - URI.parse(without_host_underscores(scheme, host, path)).tap do |uri| - uri.instance_variable_set("@host", host) - 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] - rescue StandardError - nil - end - - def self.without_host_underscores(scheme, host, path) - ["#{scheme}:/", host.tr("_", "-"), path].join("/") - end - end -end diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb index 8c652657b6..35020c5db3 100644 --- a/Library/Homebrew/cask/lib/hbc/url.rb +++ b/Library/Homebrew/cask/lib/hbc/url.rb @@ -14,7 +14,7 @@ module Hbc end def initialize(uri, options = {}) - @uri = Hbc::UnderscoreSupportingURI.parse(uri) + @uri = URI(uri) @user_agent = options.fetch(:user_agent, :default) @cookies = options[:cookies] @referer = options[:referer] diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb index ccc6a46338..bf703eba2d 100644 --- a/Library/Homebrew/test/cask/dsl/appcast_spec.rb +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -4,7 +4,7 @@ describe Hbc::DSL::Appcast do subject { described_class.new(url, params) } let(:url) { "http://example.com" } - let(:uri) { Hbc::UnderscoreSupportingURI.parse(url) } + let(:uri) { URI(url) } let(:params) { {} } describe "#to_s" do diff --git a/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb b/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb deleted file mode 100644 index 49d3ea63f7..0000000000 --- a/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe Hbc::UnderscoreSupportingURI, :cask do - describe "parse" do - it "works like normal on normal URLs" do - uri = Hbc::UnderscoreSupportingURI.parse("http://example.com/TestCask.dmg") - expect(uri).to eq(URI("http://example.com/TestCask.dmg")) - end - - it "works just fine on URIs with underscores" do - uri = Hbc::UnderscoreSupportingURI.parse("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") - expect(uri.host).to include("_") - expect(uri.to_s).to eq("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") - end - end -end