Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitbourahlavignal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIGNAL Nicolas
gitbourahlavignal
Commits
3768d582
Commit
3768d582
authored
11 years ago
by
bluemonk
Browse files
Options
Downloads
Plain Diff
Merge branch 'develop', fixes #32
parents
f495ea3a
1624d53b
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.rdoc
+1
-1
1 addition, 1 deletion
README.rdoc
lib/ipaddress.rb
+4
-9
4 additions, 9 deletions
lib/ipaddress.rb
test/ipaddress/ipv6_test.rb
+4
-3
4 additions, 3 deletions
test/ipaddress/ipv6_test.rb
test/ipaddress_test.rb
+2
-0
2 additions, 0 deletions
test/ipaddress_test.rb
with
11 additions
and
13 deletions
README.rdoc
+
1
−
1
View file @
3768d582
...
@@ -489,7 +489,7 @@ instance the following two networks:
...
@@ -489,7 +489,7 @@ instance the following two networks:
These two networks can be expressed using only one IP address
These two networks can be expressed using only one IP address
network if we change the prefix. Let Ruby do the work:
network if we change the prefix. Let Ruby do the work:
IPAddress::IPv4::summarize(ip1,ip2).to_string
IPAddress::IPv4::summarize(ip1,ip2).
map(&:
to_string
)
#=> "172.16.10.0/23"
#=> "172.16.10.0/23"
We note how the network "172.16.10.0/23" includes all the
We note how the network "172.16.10.0/23" includes all the
...
...
This diff is collapsed.
Click to expand it.
lib/ipaddress.rb
+
4
−
9
View file @
3768d582
...
@@ -135,15 +135,10 @@ module IPAddress
...
@@ -135,15 +135,10 @@ module IPAddress
# IPAddress::valid_ipv6? "2002::DEAD::BEEF"
# IPAddress::valid_ipv6? "2002::DEAD::BEEF"
# #=> false
# #=> false
#
#
def
self
.
valid_ipv6?
(
addr
)
def
self
.
valid_ipv6?
(
addr
)
# IPv6 (normal)
# https://gist.github.com/cpetschnig/294476
return
true
if
/\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*\Z/
=~
addr
# http://forums.intermapper.com/viewtopic.php?t=452
return
true
if
/\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/
=~
addr
return
true
if
/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/
=~
addr
return
true
if
/\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/
=~
addr
# IPv6 (IPv4 compat)
return
true
if
/\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/
=~
addr
&&
valid_ipv4?
(
$'
)
return
true
if
/\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/
=~
addr
&&
valid_ipv4?
(
$'
)
return
true
if
/\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/
=~
addr
&&
valid_ipv4?
(
$'
)
false
false
end
end
...
...
This diff is collapsed.
Click to expand it.
test/ipaddress/ipv6_test.rb
+
4
−
3
View file @
3768d582
...
@@ -31,7 +31,8 @@ class IPv6Test < Test::Unit::TestCase
...
@@ -31,7 +31,8 @@ class IPv6Test < Test::Unit::TestCase
"1080::8:800:200C:417A"
=>
21932261930451111902915077091070067066
}
"1080::8:800:200C:417A"
=>
21932261930451111902915077091070067066
}
@invalid_ipv6
=
[
":1:2:3:4:5:6:7"
,
@invalid_ipv6
=
[
":1:2:3:4:5:6:7"
,
":1:2:3:4:5:6:7"
]
":1:2:3:4:5:6:7"
,
"2002:516:2:200"
]
@networks
=
{
@networks
=
{
"2001:db8:1:1:1:1:1:1/32"
=>
"2001:db8::/32"
,
"2001:db8:1:1:1:1:1:1/32"
=>
"2001:db8::/32"
,
...
@@ -261,7 +262,7 @@ class IPv6Test < Test::Unit::TestCase
...
@@ -261,7 +262,7 @@ class IPv6Test < Test::Unit::TestCase
compressed
=
"2001:db8:0:cd30::"
compressed
=
"2001:db8:0:cd30::"
expanded
=
"2001:0db8:0000:cd30:0000:0000:0000:0000"
expanded
=
"2001:0db8:0000:cd30:0000:0000:0000:0000"
assert_equal
expanded
,
@klass
.
expand
(
compressed
)
assert_equal
expanded
,
@klass
.
expand
(
compressed
)
assert_not_equal
expanded
,
@klass
.
expand
(
"2001:0db8:0:cd3"
)
assert_not_equal
expanded
,
@klass
.
expand
(
"2001:0db8:0:
:
cd3"
)
assert_not_equal
expanded
,
@klass
.
expand
(
"2001:0db8::cd30"
)
assert_not_equal
expanded
,
@klass
.
expand
(
"2001:0db8::cd30"
)
assert_not_equal
expanded
,
@klass
.
expand
(
"2001:0db8::cd3"
)
assert_not_equal
expanded
,
@klass
.
expand
(
"2001:0db8::cd3"
)
end
end
...
@@ -270,7 +271,7 @@ class IPv6Test < Test::Unit::TestCase
...
@@ -270,7 +271,7 @@ class IPv6Test < Test::Unit::TestCase
compressed
=
"2001:db8:0:cd30::"
compressed
=
"2001:db8:0:cd30::"
expanded
=
"2001:0db8:0000:cd30:0000:0000:0000:0000"
expanded
=
"2001:0db8:0000:cd30:0000:0000:0000:0000"
assert_equal
compressed
,
@klass
.
compress
(
expanded
)
assert_equal
compressed
,
@klass
.
compress
(
expanded
)
assert_not_equal
compressed
,
@klass
.
compress
(
"2001:0db8:0:cd3"
)
assert_not_equal
compressed
,
@klass
.
compress
(
"2001:0db8:0:
:
cd3"
)
assert_not_equal
compressed
,
@klass
.
compress
(
"2001:0db8::cd30"
)
assert_not_equal
compressed
,
@klass
.
compress
(
"2001:0db8::cd30"
)
assert_not_equal
compressed
,
@klass
.
compress
(
"2001:0db8::cd3"
)
assert_not_equal
compressed
,
@klass
.
compress
(
"2001:0db8::cd3"
)
end
end
...
...
This diff is collapsed.
Click to expand it.
test/ipaddress_test.rb
+
2
−
0
View file @
3768d582
...
@@ -43,6 +43,8 @@ class IPAddressTest < Test::Unit::TestCase
...
@@ -43,6 +43,8 @@ class IPAddressTest < Test::Unit::TestCase
assert_equal
false
,
IPAddress
::
valid?
(
"10.0.0"
)
assert_equal
false
,
IPAddress
::
valid?
(
"10.0.0"
)
assert_equal
false
,
IPAddress
::
valid?
(
"10.0"
)
assert_equal
false
,
IPAddress
::
valid?
(
"10.0"
)
assert_equal
false
,
IPAddress
::
valid?
(
"2002:::1"
)
assert_equal
false
,
IPAddress
::
valid?
(
"2002:::1"
)
assert_equal
false
,
IPAddress
::
valid?
(
"2002:516:2:200"
)
end
end
def
test_module_method_valid_ipv4_netmark?
def
test_module_method_valid_ipv4_netmark?
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment