Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: sporkmonger/addressable
base: master
...
head fork: dlee/addressable
compare: add_default_port
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
2  addressable.gemspec
@@ -13,7 +13,7 @@ adds support for IRIs and URI templates.
}
s.email = %q{bob@sporkmonger.com}
s.extra_rdoc_files = ["README.md"]
- s.files = ["lib/addressable", "lib/addressable/idna", "lib/addressable/idna/native.rb", "lib/addressable/idna/pure.rb", "lib/addressable/idna.rb", "lib/addressable/template.rb", "lib/addressable/uri.rb", "lib/addressable/version.rb", "spec/addressable", "spec/addressable/idna_spec.rb", "spec/addressable/net_http_compat_spec.rb", "spec/addressable/template_spec.rb", "spec/addressable/uri_spec.rb", "tasks/clobber.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/metrics.rake", "tasks/rspec.rake", "tasks/rubyforge.rake", "tasks/yard.rake", "website/index.html", "CHANGELOG.md", "Gemfile", "Gemfile.lock", "LICENSE.txt", "Rakefile", "README.md"]
+ s.files = ["lib/addressable", "lib/addressable/idna", "lib/addressable/idna/native.rb", "lib/addressable/idna/pure.rb", "lib/addressable/idna.rb", "lib/addressable/template.rb", "lib/addressable/uri.rb", "lib/addressable/version.rb", "spec/addressable", "spec/addressable/idna_spec.rb", "spec/addressable/net_http_compat_spec.rb", "spec/addressable/template_spec.rb", "spec/addressable/uri_spec.rb", "tasks/clobber.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/metrics.rake", "tasks/rspec.rake", "tasks/rubyforge.rake", "tasks/yard.rake", "website/index.html", "CHANGELOG.md", "Gemfile", "LICENSE.txt", "Rakefile", "README.md"]
s.homepage = %q{http://addressable.rubyforge.org/}
s.rdoc_options = ["--main", "README.md"]
s.require_paths = ["lib"]
View
16 lib/addressable/uri.rb
@@ -1201,17 +1201,23 @@ def port=(new_port)
# @return [Integer] The inferred port component.
def inferred_port
if self.port.to_i == 0
- if self.scheme
- URI.port_mapping[self.scheme.strip.downcase]
- else
- nil
- end
+ self.default_port
else
self.port.to_i
end
end
##
+ # The default port for this URI's scheme.
+ # This method will always returns the default port for the URI's scheme
+ # regardless of the presence of an explicit port in the URI.
+ #
+ # @return [Integer] The default port.
+ def default_port
+ URI.port_mapping[self.scheme.strip.downcase] if self.scheme
+ end
+
+ ##
# The combination of components that represent a site.
# Combines the scheme, user, password, host, and port components.
# Primarily useful for HTTP and HTTPS.
View
63 spec/addressable/uri_spec.rb
@@ -167,6 +167,10 @@ def to_s
@uri.to_s.should == ""
end
+ it "should have a nil default port" do
+ @uri.default_port.should == nil
+ end
+
it "should raise an error if the scheme is set to whitespace" do
(lambda do
@uri.scheme = "\t \n"
@@ -267,6 +271,10 @@ def to_s
@uri.normalized_port.should == nil
end
+ it "returns nil for #default_port" do
+ @uri.default_port.should == nil
+ end
+
it "returns nil for #site" do
@uri.site.should == nil
end
@@ -359,6 +367,7 @@ def to_s
it "should not infer a port" do
@uri.port.should == nil
+ @uri.default_port.should == nil
@uri.inferred_port.should == nil
end
@@ -506,6 +515,10 @@ def to_s
@uri.host.should == "ftp.is.co.za"
end
+ it "should have inferred_port of 21" do
+ @uri.inferred_port.should == 21
+ end
+
it "should have a path of '/rfc/rfc1808.txt'" do
@uri.path.should == "/rfc/rfc1808.txt"
end
@@ -542,6 +555,10 @@ def to_s
@uri.host.should == "www.ietf.org"
end
+ it "should have inferred_port of 80" do
+ @uri.inferred_port.should == 80
+ end
+
it "should have a path of '/rfc/rfc2396.txt'" do
@uri.path.should == "/rfc/rfc2396.txt"
end
@@ -588,6 +605,10 @@ def to_s
@uri.host.should == "[2001:db8::7]"
end
+ it "should have inferred_port of 389" do
+ @uri.inferred_port.should == 389
+ end
+
it "should have a path of '/c=GB'" do
@uri.path.should == "/c=GB"
end
@@ -646,6 +667,10 @@ def to_s
@uri.should_not be_ip_based
end
+ it "should not have an inferred_port" do
+ @uri.inferred_port.should == nil
+ end
+
it "should have a path of 'John.Doe@example.com'" do
@uri.path.should == "John.Doe@example.com"
end
@@ -674,6 +699,10 @@ def to_s
@uri.scheme.should == "news"
end
+ it "should not have an inferred_port" do
+ @uri.inferred_port.should == nil
+ end
+
it "should not be considered to be ip-based" do
@uri.should_not be_ip_based
end
@@ -710,6 +739,10 @@ def to_s
@uri.should_not be_ip_based
end
+ it "should not have an inferred_port" do
+ @uri.inferred_port.should == nil
+ end
+
it "should have a path of '+1-816-555-1212'" do
@uri.path.should == "+1-816-555-1212"
end
@@ -742,10 +775,18 @@ def to_s
@uri.host.should == "192.0.2.16"
end
- it "should have a port of '80'" do
+ it "should have a port of 80" do
@uri.port.should == 80
end
+ it "should have a inferred_port of 80" do
+ @uri.inferred_port.should == 80
+ end
+
+ it "should have a default_port of 23" do
+ @uri.default_port.should == 23
+ end
+
it "should be considered to be ip-based" do
@uri.should be_ip_based
end
@@ -779,6 +820,10 @@ def to_s
@uri.scheme.should == "urn"
end
+ it "should not have an inferred_port" do
+ @uri.inferred_port.should == nil
+ end
+
it "should not be considered to be ip-based" do
@uri.should_not be_ip_based
end
@@ -1593,6 +1638,10 @@ def to_s
end
it "should use port 80" do
+ @uri.inferred_port.should == 80
+ end
+
+ it "should have explicit port 80" do
@uri.port.should == 80
end
@@ -1709,9 +1758,17 @@ def to_s
end
it "should use port 8080" do
+ @uri.inferred_port.should == 8080
+ end
+
+ it "should have explicit port 8080" do
@uri.port.should == 8080
end
+ it "should have default port 80" do
+ @uri.default_port.should == 80
+ end
+
it "should have a path of '/'" do
@uri.path.should == "/"
end
@@ -3039,6 +3096,10 @@ def to_s
@uri.host.should == "example.com"
end
+ it "should have default_port 80" do
+ @uri.default_port.should == 80
+ end
+
it "should use port 80" do
@uri.inferred_port.should == 80
end

No commit comments for this range

Something went wrong with that request. Please try again.