-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove negative check for nil
#446
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,10 +131,10 @@ def self.parse(uri) | |
password = nil | ||
host = nil | ||
port = nil | ||
if authority != nil | ||
if authority | ||
# The Regexp above doesn't split apart the authority. | ||
userinfo = authority[/^([^\[\]]*)@/, 1] | ||
if userinfo != nil | ||
if userinfo | ||
user = userinfo.strip[/^([^:]*):?/, 1] | ||
password = userinfo.strip[/:(.*)$/, 1] | ||
end | ||
|
@@ -685,7 +685,7 @@ def self.normalized_encode(uri, return_type=String) | |
:fragment => self.unencode_component(uri_object.fragment) | ||
} | ||
components.each do |key, value| | ||
if value != nil | ||
if value | ||
begin | ||
components[key] = | ||
Addressable::IDNA.unicode_normalize_kc(value.to_str) | ||
|
@@ -969,7 +969,7 @@ def user=(new_user) | |
@user = new_user ? new_user.to_str : nil | ||
|
||
# You can't have a nil user with a non-nil password | ||
if password != nil | ||
if password | ||
@user = EMPTY_STR if @user.nil? | ||
end | ||
|
||
|
@@ -1030,7 +1030,7 @@ def password=(new_password) | |
# You can't have a nil user with a non-nil password | ||
@password ||= nil | ||
@user ||= nil | ||
if @password != nil | ||
if @password | ||
@user = EMPTY_STR if @user.nil? | ||
end | ||
|
||
|
@@ -1241,11 +1241,11 @@ def domain | |
def authority | ||
self.host && @authority ||= begin | ||
authority = String.new | ||
if self.userinfo != nil | ||
if self.userinfo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
authority << "#{self.userinfo}@" | ||
end | ||
authority << self.host | ||
if self.port != nil | ||
if self.port | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
authority << ":#{self.port}" | ||
end | ||
authority | ||
|
@@ -1260,11 +1260,11 @@ def normalized_authority | |
return nil unless self.authority | ||
@normalized_authority ||= begin | ||
authority = String.new | ||
if self.normalized_userinfo != nil | ||
if self.normalized_userinfo | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
authority << "#{self.normalized_userinfo}@" | ||
end | ||
authority << self.normalized_host | ||
if self.normalized_port != nil | ||
if self.normalized_port | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
authority << ":#{self.normalized_port}" | ||
end | ||
authority | ||
|
@@ -1417,17 +1417,16 @@ def normalized_port | |
# | ||
# @param [String, Integer, #to_s] new_port The new port component. | ||
def port=(new_port) | ||
if new_port != nil && new_port.respond_to?(:to_str) | ||
if new_port && new_port.respond_to?(:to_str) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method. |
||
new_port = Addressable::URI.unencode_component(new_port.to_str) | ||
end | ||
|
||
if new_port.respond_to?(:valid_encoding?) && !new_port.valid_encoding? | ||
raise InvalidURIError, "Invalid encoding in port" | ||
end | ||
|
||
if new_port != nil && !(new_port.to_s =~ /^\d+$/) | ||
raise InvalidURIError, | ||
"Invalid port number: #{new_port.inspect}" | ||
if new_port && !(new_port.to_s =~ /^\d+$/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/InverseMethods: Use !~ instead of inverting =~. |
||
raise InvalidURIError, "Invalid port number: #{new_port.inspect}" | ||
end | ||
|
||
@port = new_port.to_s.to_i | ||
|
@@ -1478,8 +1477,8 @@ def default_port | |
def site | ||
(self.scheme || self.authority) && @site ||= begin | ||
site_string = "".dup | ||
site_string << "#{self.scheme}:" if self.scheme != nil | ||
site_string << "//#{self.authority}" if self.authority != nil | ||
site_string << "#{self.scheme}:" if self.scheme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
site_string << "//#{self.authority}" if self.authority | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
site_string | ||
end | ||
end | ||
|
@@ -1497,10 +1496,10 @@ def normalized_site | |
return nil unless self.site | ||
@normalized_site ||= begin | ||
site_string = "".dup | ||
if self.normalized_scheme != nil | ||
if self.normalized_scheme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
site_string << "#{self.normalized_scheme}:" | ||
end | ||
if self.normalized_authority != nil | ||
if self.normalized_authority | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
site_string << "//#{self.normalized_authority}" | ||
end | ||
site_string | ||
|
@@ -1582,7 +1581,7 @@ def path=(new_path) | |
raise TypeError, "Can't convert #{new_path.class} into String." | ||
end | ||
@path = (new_path || EMPTY_STR).to_str | ||
if [email protected]? && @path[0..0] != SLASH && host != nil | ||
if [email protected]? && @path[0..0] != SLASH && host | ||
@path = "/#{@path}" | ||
end | ||
|
||
|
@@ -1927,7 +1926,7 @@ def join(uri) | |
joined_fragment = nil | ||
|
||
# Section 5.2.2 of RFC 3986 | ||
if uri.scheme != nil | ||
if uri.scheme | ||
joined_scheme = uri.scheme | ||
joined_user = uri.user | ||
joined_password = uri.password | ||
|
@@ -1936,7 +1935,7 @@ def join(uri) | |
joined_path = URI.normalize_path(uri.path) | ||
joined_query = uri.query | ||
else | ||
if uri.authority != nil | ||
if uri.authority | ||
joined_user = uri.user | ||
joined_password = uri.password | ||
joined_host = uri.host | ||
|
@@ -1946,7 +1945,7 @@ def join(uri) | |
else | ||
if uri.path == nil || uri.path.empty? | ||
joined_path = self.path | ||
if uri.query != nil | ||
if uri.query | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/BlockNesting: Avoid more than 3 levels of block nesting. |
||
joined_query = uri.query | ||
else | ||
joined_query = self.query | ||
|
@@ -1970,7 +1969,7 @@ def join(uri) | |
|
||
# If the base path is empty and an authority segment has been | ||
# defined, use a base path of SLASH | ||
if base_path.empty? && self.authority != nil | ||
if base_path.empty? && self.authority | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
base_path = SLASH | ||
end | ||
|
||
|
@@ -2142,7 +2141,7 @@ def route_from(uri) | |
end | ||
end | ||
# Avoid network-path references. | ||
if components[:host] != nil | ||
if components[:host] | ||
components[:scheme] = normalized_self.scheme | ||
end | ||
return Addressable::URI.new( | ||
|
@@ -2358,18 +2357,18 @@ def empty? | |
# | ||
# @return [String] The URI's <code>String</code> representation. | ||
def to_s | ||
if self.scheme == nil && self.path != nil && !self.path.empty? && | ||
if self.scheme == nil && self.path && !self.path.empty? && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
self.path =~ NORMPATH | ||
raise InvalidURIError, | ||
"Cannot assemble URI string with ambiguous path: '#{self.path}'" | ||
end | ||
@uri_string ||= begin | ||
uri_string = String.new | ||
uri_string << "#{self.scheme}:" if self.scheme != nil | ||
uri_string << "//#{self.authority}" if self.authority != nil | ||
uri_string << "#{self.scheme}:" if self.scheme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
uri_string << "//#{self.authority}" if self.authority | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
uri_string << self.path.to_s | ||
uri_string << "?#{self.query}" if self.query != nil | ||
uri_string << "##{self.fragment}" if self.fragment != nil | ||
uri_string << "?#{self.query}" if self.query | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
uri_string << "##{self.fragment}" if self.fragment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
uri_string.force_encoding(Encoding::UTF_8) | ||
uri_string | ||
end | ||
|
@@ -2474,25 +2473,25 @@ def self.normalize_path(path) | |
# Ensures that the URI is valid. | ||
def validate | ||
return if !!@validation_deferred | ||
if self.scheme != nil && self.ip_based? && | ||
if self.scheme && self.ip_based? && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
(self.host == nil || self.host.empty?) && | ||
(self.path == nil || self.path.empty?) | ||
raise InvalidURIError, | ||
"Absolute URI missing hierarchical segment: '#{self.to_s}'" | ||
end | ||
if self.host == nil | ||
if self.port != nil || | ||
self.user != nil || | ||
self.password != nil | ||
if self.port || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
self.user || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/MultilineOperationIndentation: Align the operands of a condition in an if statement spanning multiple lines. |
||
self.password | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/MultilineOperationIndentation: Align the operands of a condition in an if statement spanning multiple lines. |
||
raise InvalidURIError, "Hostname not supplied: '#{self.to_s}'" | ||
end | ||
end | ||
if self.path != nil && !self.path.empty? && self.path[0..0] != SLASH && | ||
self.authority != nil | ||
if self.path && !self.path.empty? && self.path[0..0] != SLASH && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
self.authority | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/MultilineOperationIndentation: Align the operands of a condition in an if statement spanning multiple lines. |
||
raise InvalidURIError, | ||
"Cannot have a relative path with an authority set: '#{self.to_s}'" | ||
end | ||
if self.path != nil && !self.path.empty? && | ||
if self.path && !self.path.empty? && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected. |
||
self.path[0..1] == SLASH + SLASH && self.authority == nil | ||
raise InvalidURIError, | ||
"Cannot have a path with two leading slashes " + | ||
|
@@ -2501,7 +2500,7 @@ def validate | |
unreserved = CharacterClasses::UNRESERVED | ||
sub_delims = CharacterClasses::SUB_DELIMS | ||
if !self.host.nil? && (self.host =~ /[<>{}\/\\\?\#\@"[[:space:]]]/ || | ||
(self.host[/^\[(.*)\]$/, 1] != nil && self.host[/^\[(.*)\]$/, 1] !~ | ||
(self.host[/^\[(.*)\]$/, 1] && self.host[/^\[(.*)\]$/, 1] !~ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/RedundantSelf: Redundant self detected.
This comment was marked as spam.
Sorry, something went wrong. |
||
Regexp.new("^[#{unreserved}#{sub_delims}:]*$"))) | ||
raise InvalidURIError, "Invalid character in host: '#{self.host.to_s}'" | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/Next: Use next to skip iteration.