[Rt-commit] [rtir] 01/02: Use \b as a stronger limiter for before IP addresses
Alex Vandiver
alexmv at bestpractical.com
Wed Mar 25 12:45:57 EDT 2015
This is an automated email from the git hooks/post-receive script.
alexmv pushed a commit to branch 3.0/ipv6-regex
in repository rtir.
commit fc0dfd1bacdf05fdea5de4b4f9e2db870ba6939d
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Mon Mar 23 16:37:32 2015 -0400
Use \b as a stronger limiter for before IP addresses
Previously, "doesn't come after any possible IP characters" was the
limit. For IPv6 addresses, however, this caused unwanted behavior:
dead:beef:: => dead:beef::
:dead:beef:: => ead:beef::
qdead:beef:: => dead:beef::
meathead:beef:: => ead:beef::
IPv6:dead:beef:: => 6:dead:beef::
wrong:dead:beef:: => ead:beef::
There is no harm in allowing an IPv6 address to follow after a colon.
Additionally, to ensure that "IPv6:dead:beef::" does not merely take the
"6", limit both IPv4 and IPv6 addresses to coming at a word boundary.
With these changes, we obtain:
dead:beef:: => dead:beef::
:dead:beef:: => dead:beef::
qdead:beef:: => beef::
meathead:beef:: => beef::
IPv6:dead:beef:: => dead:beef::
wrong:dead:beef:: => dead:beef::
All of which are more expected. Note that this also causes
"base64.1.2.3" to no longer match as an IPv4 address; this is considered
to be an appropriate change.
Fixes: I#30643
---
lib/RT/Action/RTIR_FindIP.pm | 4 ++--
t/custom-fields/ipv6.t | 6 +++++-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/lib/RT/Action/RTIR_FindIP.pm b/lib/RT/Action/RTIR_FindIP.pm
index 2ac4c39..c65eed2 100644
--- a/lib/RT/Action/RTIR_FindIP.pm
+++ b/lib/RT/Action/RTIR_FindIP.pm
@@ -58,7 +58,7 @@ use Regexp::IPv6 qw();
use Net::CIDR ();
my $IPv4_mask_re = qr{3[0-2]|[1-2]?[0-9]};
-my $IPv4_prefix_check_re = qr{(?<![0-9.])};
+my $IPv4_prefix_check_re = qr{(?:^|\b)(?<![0-9.])};
my $IPv4_sufix_check_re = qr{(?!\.?[0-9])};
my $IPv4_CIDR_re = qr{
$IPv4_prefix_check_re
@@ -74,7 +74,7 @@ my $IPv4_re = qr[
]x;
my $IPv6_mask_re = qr{12[0-8]|1[01][0-9]|[1-9]?[0-9]};
-my $IPv6_prefix_check_re = qr{(?<![0-9a-fA-F:.])};
+my $IPv6_prefix_check_re = qr{(?:^|\b)(?<![0-9.])};
my $IPv6_sufix_check_re = qr{(?!(?:\:{0,2}|\.)[0-9a-fA-F])};
my $IPv6_re = qr[
$IPv6_prefix_check_re
diff --git a/t/custom-fields/ipv6.t b/t/custom-fields/ipv6.t
index 768ebe1..0c83d2f 100644
--- a/t/custom-fields/ipv6.t
+++ b/t/custom-fields/ipv6.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::IR::Test tests => 698;
+use RT::IR::Test tests => undef;
RT::Test->started_ok;
my $agent = default_agent();
@@ -24,6 +24,8 @@ my %test_set = (
'abcd:' x 7 . 'abcd' => 'abcd:' x 7 . 'abcd',
'abcd::034' => 'abcd:' . '0000:' x 6 . '0034',
'::192.168.1.1' => '0000:' x 6 . 'c0a8:0101',
+ 'IPv6:abcd::034' => 'abcd:' . '0000:' x 6 . '0034',
+ 'qabcd::034' => '0000:' x 7 . '0034',
);
my %test_cidr = (
'abcd:' x 7 . 'abcd/32' => 'abcd:abcd'. ':0000' x 6 .'-'. 'abcd:abcd'. ':ffff' x 6,
@@ -555,3 +557,5 @@ diag "merge ticket with the same IP";
is( $has[0], '0000:'x6 .'ac10:0001', "has value" );
}
+undef $agent;
+done_testing;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the rt-commit
mailing list