Merge remote-tracking branch 'origin/master' into gh

This commit is contained in:
Owen Ou 2014-10-17 16:02:37 -07:00
Родитель a39ce5428c 3fad589b6e
Коммит 11f0eb39d6
5 изменённых файлов: 84 добавлений и 9 удалений

Просмотреть файл

@ -141,6 +141,7 @@ Scenario: Related fork already exists
""" """
before { before {
halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'http' halt 400 unless request.env['HTTP_X_ORIGINAL_SCHEME'] == 'http'
halt 400 unless request.env['HTTP_X_ORIGINAL_PORT'] == '80'
halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN' halt 401 unless request.env['HTTP_AUTHORIZATION'] == 'token FITOKEN'
} }
post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') { '' } post('/api/v3/repos/evilchelu/dotfiles/forks', :host_name => 'git.my.org') { '' }

Просмотреть файл

@ -273,13 +273,15 @@ module Hub
def configure_connection req, url def configure_connection req, url
url.scheme = config.protocol(url.host) url.scheme = config.protocol(url.host)
url.port = 80 if url.scheme == 'http'
if ENV['HUB_TEST_HOST'] if ENV['HUB_TEST_HOST']
req['Host'] = url.host req['Host'] = url.host
req['X-Original-Scheme'] = url.scheme req['X-Original-Scheme'] = url.scheme
req['X-Original-Port'] = url.port
url = url.dup url = url.dup
url.scheme = 'http' url.scheme = 'http'
url.host, test_port = ENV['HUB_TEST_HOST'].split(':') url.host, test_port = ENV['HUB_TEST_HOST'].split(':')
url.port = test_port.to_i if test_port url.port = test_port ? test_port.to_i : 80
end end
yield url yield url
end end

Просмотреть файл

@ -33,7 +33,9 @@ unless defined?(URI)
end end
module URI module URI
InvalidURIError = Class.new(StandardError) Error = Class.new(StandardError)
InvalidURIError = Class.new(Error)
InvalidComponentError = Class.new(Error)
def self.parse(str) def self.parse(str)
URI::HTTP.new(str) URI::HTTP.new(str)
@ -56,23 +58,24 @@ unless defined?(URI)
class HTTP class HTTP
attr_accessor :scheme, :user, :password, :host, :path, :query, :fragment attr_accessor :scheme, :user, :password, :host, :path, :query, :fragment
attr_writer :port attr_reader :port
alias hostname host alias hostname host
def initialize(str) def initialize(str)
m = str.to_s.match(%r{^ ([\w-]+): // (?:([^/@]+)@)? ([^/?#]+) }x) m = str.to_s.match(%r{^ ([\w-]+): // (?:([^/@]+)@)? ([^/?#]+) }x)
raise InvalidURIError unless m raise InvalidURIError unless m
_, self.scheme, self.userinfo, host = m.to_a _, self.scheme, self.userinfo, host = m.to_a
self.host, self.port = host.split(':', 2) self.host, port = host.split(':', 2)
self.port = port ? port.to_i : default_port
path, self.fragment = m.post_match.split('#', 2) path, self.fragment = m.post_match.split('#', 2)
self.path, self.query = path.to_s.split('?', 2) path, self.query = path.split('?', 2) if path
self.path = path.to_s
end end
def to_s def to_s
url = "#{scheme}://" url = "#{scheme}://"
url << "#{userinfo}@" if user || password url << "#{userinfo}@" if user || password
url << host url << host << display_port
url << ":#{@port}" if @port
url << path url << path
url << "?#{query}" if query url << "?#{query}" if query
url << "##{fragment}" if fragment url << "##{fragment}" if fragment
@ -85,8 +88,12 @@ unless defined?(URI)
url url
end end
def port def port=(number)
(@port || (scheme == 'https' ? 443 : 80)).to_i if number.is_a?(Fixnum) && number > 0
@port = number
else
raise InvalidComponentError, "bad component(expected port component): %p" % number
end
end end
def userinfo=(info) def userinfo=(info)
@ -102,6 +109,20 @@ unless defined?(URI)
def find_proxy def find_proxy
end end
private
def default_port
self.scheme == 'https' ? 443 : 80
end
def display_port
if port != default_port
":#{port}"
else
""
end
end
end end
end end
end end

Просмотреть файл

@ -1,3 +1,8 @@
if defined?(Bundler) && defined?(URI)
Object.send(:remove_const, :URI)
$".reject! { |p| p =~ %r{(^|/)uri[/.]} }
end
require 'minitest/autorun' require 'minitest/autorun'
require 'hub' require 'hub'

Просмотреть файл

@ -0,0 +1,46 @@
require 'helper'
class URITest < Minitest::Test
def test_uri_is_from_speedy_stdlib
# if it were stdlib, URI::HTTPS would be the result
assert_equal URI::HTTP, URI.parse("https://example.com").class
end
def test_uri_display_port
assert_equal "https://example.com", URI.parse("https://example.com").to_s
assert_equal "https://example.com:80", URI.parse("https://example.com:80").to_s
assert_equal "http://example.com", URI.parse("http://example.com").to_s
assert_equal "http://example.com:443", URI.parse("http://example.com:443").to_s
end
def test_uri_invalid_port
assert_raises URI::InvalidComponentError do
uri = URI.parse("https://example.com")
uri.port = "80"
end
end
def test_uri_scheme_doesnt_affect_port
uri = URI.parse("https://example.com")
uri.scheme = "http"
assert_equal "http", uri.scheme
assert_equal 443, uri.port
uri.port = 80
assert_equal 80, uri.port
end
def test_blank_path
uri = URI.parse("https://example.com")
assert_equal "", uri.path
end
def test_no_query
uri = URI.parse("https://example.com")
assert_nil uri.query
end
def test_blank_query
uri = URI.parse("https://example.com?")
assert_equal "", uri.query
end
end