Skip to content

Commit

Permalink
correct instances of strip! mutating string provided to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinhirne committed Aug 23, 2019
1 parent 38a4a64 commit 31e6f1d
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/ipv4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(i)
# parse will create an IPv4 from its string representation (ie. "192.168.1.1").
# Throws ValidationError on error.
def IPv4.parse(ip)
ip.strip!
ip = ip.strip
i = Util.parse_IPv4(ip)
return IPv4.new(i)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ipv4net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(ip,m32)
# parse will create an IPv4Net from its string representation. Will default to a /32 netmask if not specified.
# Throws ValidationError on error.
def IPv4Net.parse(net)
net.strip!
net = net.strip
m32 = nil
if (net.include?("/")) # cidr format
addr,mask = net.split("/")
Expand Down
2 changes: 1 addition & 1 deletion lib/ipv6.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(i)
# parse will create an IPv6 from its string representation (ie. "1::").
# Throws ValidationError on error.
def IPv6.parse(ip)
ip.strip!
ip = ip.strip
i = Util.parse_IPv6(ip)
return IPv6.new(i)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ipv6net.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(ip,m128)
# Throws ValidationError on error.
def IPv6Net.parse(net)
m128 = nil
net.strip!
net = net.strip
if (net.include?("/")) # cidr format
addr,mask = net.split("/")
m128 = Mask128.parse(mask)
Expand Down
2 changes: 1 addition & 1 deletion lib/mask128.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(prefix_len)
#
# Throws ValidationError on error.
def Mask128.parse(mask)
mask.strip!
mask = mask.strip
if (mask.start_with?("/")) # cidr format
mask = mask[1..-1] # remove "/"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mask32.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(prefix_len)
#
# Throws ValidationError on error.
def Mask32.parse(mask)
mask.strip!
mask = mask.strip
if (mask.start_with?("/")) # cidr format
mask = mask[1..-1] # remove "/"
end
Expand Down
5 changes: 2 additions & 3 deletions lib/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ def Util.parse_IPv4(ip)
raise ValidationError, "#{ip} contains invalid characters."
end

ip.strip!
octets = ip.split('.')
octets = ip.strip.split('.')
if (octets.length != 4)
raise ValidationError, "IPv4 requires (4) octets."
end
Expand All @@ -190,7 +189,7 @@ def Util.parse_IPv6(ip)
raise ValidationError, "#{ip} contains invalid characters."
end

ip.strip!
ip = ip.strip
if (ip == "::")
return 0 # zero address
end
Expand Down

0 comments on commit 31e6f1d

Please sign in to comment.