1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/uri/http.rb: Documentation and code style imrovements.

* test/uri/test_http.rb: Added test for coverage.
  [fix GH-1427][ruby-core:77255][Misc #12756]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2016-09-30 10:06:24 +00:00
parent 377f69e4fe
commit 107ba65fba
3 changed files with 30 additions and 16 deletions

View file

@ -1,3 +1,9 @@
Fri Sep 30 19:06:21 2016 Anton Davydov <mail@davydovanton.com>
* lib/uri/http.rb: Documentation and code style imrovements.
* test/uri/test_http.rb: Added test for coverage.
[fix GH-1427][ruby-core:77255][Misc #12756]
Fri Sep 30 18:43:20 2016 Jason Yeo <jason@jasonyeo.me>
* doc/syntax/control_expressions.rdoc: Add missing 'as'

View file

@ -25,12 +25,12 @@ module URI
DEFAULT_PORT = 80
# An Array of the available components for URI::HTTP
COMPONENT = [
:scheme,
:userinfo, :host, :port,
:path,
:query,
:fragment
COMPONENT = %i[
scheme
userinfo host port
path
query
fragment
].freeze
#
@ -49,8 +49,7 @@ module URI
#
# Example:
#
# newuri = URI::HTTP.build({:host => 'www.example.com',
# :path => '/foo/bar'})
# newuri = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
#
# newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
# "query", 'fragment'])
@ -59,8 +58,8 @@ module URI
# invalid HTTP URIs as per RFC 1738.
#
def self.build(args)
tmp = Util::make_components_hash(self, args)
return super(tmp)
tmp = Util.make_components_hash(self, args)
super(tmp)
end
=begin
@ -95,15 +94,19 @@ module URI
# If the URI contains a query, the full path is URI#path + '?' + URI#query.
# Otherwise, the path is simply URI#path.
#
# Example:
#
# newuri = URI::HTTP.build(path: '/foo/bar', query: 'test=true')
# newuri.request_uri # => "/foo/bar?test=true"
#
def request_uri
return nil unless @path
if @path.start_with?(?/.freeze)
@query ? "#@path?#@query" : @path.dup
else
@query ? "/#@path?#@query" : "/#@path"
end
return unless @path
url = @query ? "#@path?#@query" : @path.dup
url.start_with?(?/.freeze) ? url : ?/ + url
end
end
@@schemes['HTTP'] = HTTP
end

View file

@ -16,6 +16,11 @@ class TestHTTP < Test::Unit::TestCase
uri.class.component.collect {|c| uri.send(c)}
end
def test_build
u = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
assert_kind_of(URI::HTTP, u)
end
def test_parse
u = URI.parse('http://a')
assert_kind_of(URI::HTTP, u)