[Rt-commit] rt branch, 4.4/compress-ipv6, created. rt-4.2.11-237-gfdd4ca8

? sunnavy sunnavy at bestpractical.com
Fri Oct 9 12:41:57 EDT 2015


The branch, 4.4/compress-ipv6 has been created
        at  fdd4ca845d3b624c9ea0b01de8a5cfaf2c3add50 (commit)

- Log -----------------------------------------------------------------
commit fdd4ca845d3b624c9ea0b01de8a5cfaf2c3add50
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Oct 10 00:34:57 2015 +0800

    show compressed ipv6, which is shorter and more clear

diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
index 92a0e02..4579a38 100644
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@ -228,9 +228,13 @@ sub Content {
         || $self->CustomFieldObj->Type eq 'IPAddressRange' )
     {
 
+        require Net::IP;
         if ( $content =~ /^\s*($re_ip_serialized)\s*$/o ) {
             $content = sprintf "%d.%d.%d.%d", split /\./, $1;
         }
+        if ( $content =~ /^\s*($IPv6_re)\s*$/o ) {
+            $content = Net::IP::ip_compress_address($1, 6);
+        }
 
         return $content if $self->CustomFieldObj->Type eq 'IPAddress';
 
@@ -245,7 +249,7 @@ sub Content {
             }
         }
         elsif ( $large_content =~ /^\s*($IPv6_re)\s*$/o ) {
-            my $eIP = $1;
+            my $eIP = Net::IP::ip_compress_address($1, 6);
             if ( $content eq $eIP ) {
                 return $content;
             }
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index b16bae3..210dbec 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -244,6 +244,7 @@ MIME::Entity 5.504
 Module::Refresh 0.03
 Module::Versions::Report 1.05
 Net::CIDR
+Net::IP
 Plack 1.0002
 Plack::Handler::Starlet
 Regexp::Common
diff --git a/t/customfields/iprangev6.t b/t/customfields/iprangev6.t
index 445df33..896be52 100644
--- a/t/customfields/iprangev6.t
+++ b/t/customfields/iprangev6.t
@@ -40,13 +40,13 @@ diag "check that CF applies to queue General" if $ENV{'TEST_VERBOSE'};
 
 my %valid = (
     'abcd:' x 7 . 'abcd' => 'abcd:' x 7 . 'abcd',
-    '034:' x 7 . '034'   => '0034:' x 7 . '0034',
-    'abcd::'             => 'abcd:' . '0000:' x 6 . '0000',
-    '::abcd'             => '0000:' x 7 . 'abcd',
-    'abcd::034'          => 'abcd:' . '0000:' x 6 . '0034',
-    'abcd::192.168.1.1'  => 'abcd:' . '0000:' x 5 . 'c0a8:0101',
-    '::192.168.1.1'      => '0000:' x 6 . 'c0a8:0101',
-    '::'                 => '0000:' x 7 . '0000',
+    '034:' x 7 . '034'   => '34:' x 7 . '34',
+    'abcd::'             => 'abcd::',
+    '::abcd'             => '::abcd',
+    'abcd::034'          => 'abcd::34',
+    'abcd::192.168.1.1'  => 'abcd::c0a8:101',
+    '::192.168.1.1'      => '::c0a8:101',
+    '::'                 => '::',
 );
 
 diag "create a ticket via web and set IP" if $ENV{'TEST_VERBOSE'};
@@ -95,7 +95,7 @@ diag "create a ticket via web with CIDR" if $ENV{'TEST_VERBOSE'};
     ok( $ticket->id, 'loaded ticket' );
     is(
         $ticket->FirstCustomFieldValue('IP'),
-'abcd:0034:0000:0000:0000:0000:0000:0000-abcd:0035:ffff:ffff:ffff:ffff:ffff:ffff',
+'abcd:34::-abcd:35:ffff:ffff:ffff:ffff:ffff:ffff',
         'correct value'
     );
 }
@@ -149,7 +149,7 @@ diag "create a ticket and edit IP field using Edit page" if $ENV{'TEST_VERBOSE'}
         "Followed 'Basics' link" );
     $agent->form_name('TicketModify');
     is( $agent->value($cf_field), $val, 'IP is in input box' );
-    $val = 'abcd' . ':0000' x 7 . '-' . 'abcd' . ':ffff' x 7;
+    $val = 'abcd::' . '-' . 'abcd' . ':ffff' x 7;
     $agent->field( $cf_field => 'abcd::/16' );
     $agent->click('SubmitTicket');
 
@@ -165,7 +165,7 @@ diag "create a ticket and edit IP field using Edit page" if $ENV{'TEST_VERBOSE'}
         "Followed 'Basics' link" );
     $agent->form_name('TicketModify');
     is( $agent->value($cf_field), $val, 'IP is in input box' );
-    $val = 'bb00' . ':0000' x 7 . '-' . 'bbff' . ':ffff' x 7;
+    $val = 'bb::' . '-' . 'bbff' . ':ffff' x 7;
     $agent->field( $cf_field => $val );
     $agent->click('SubmitTicket');
 
@@ -224,7 +224,7 @@ diag "search tickets by IP" if $ENV{'TEST_VERBOSE'};
     ok( $tickets->Count, "found tickets" );
     is(
         $ticket->FirstCustomFieldValue('IP'),
-'abcd:0000:0000:0000:0000:0000:0000:0000-abcd:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
+'abcd::-abcd:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
         'correct value'
     );
 }
@@ -256,7 +256,7 @@ diag "search tickets by IP range" if $ENV{'TEST_VERBOSE'};
 
     is(
         $ticket->FirstCustomFieldValue('IP'),
-'abcd:ef00:0000:0000:0000:0000:0000:0000-abcd:efff:ffff:ffff:ffff:ffff:ffff:ffff',
+'abcd:ef00::-abcd:efff:ffff:ffff:ffff:ffff:ffff:ffff',
         'correct value'
     );
 }
@@ -265,8 +265,8 @@ diag "create two tickets with different IPs and check several searches" if $ENV{
 {
     ok $agent->goto_create_ticket($q), "go to create ticket";
     my $cf_field = "Object-RT::Ticket--CustomField-$cf_id-Values";
-    my $first_ip = 'cbcd' . ':0000' x 7;
-    my $second_ip = 'cbdd' . ':0000' x 7;
+    my $first_ip = 'cbcd::';
+    my $second_ip = 'cbdd::';
     $agent->submit_form(
         form_name => 'TicketCreate',
         fields    => {
diff --git a/t/customfields/ipv6.t b/t/customfields/ipv6.t
index 24f7c2a..d1bca36 100644
--- a/t/customfields/ipv6.t
+++ b/t/customfields/ipv6.t
@@ -45,13 +45,14 @@ diag "check that CF applies to queue General" if $ENV{'TEST_VERBOSE'};
 
 my %valid = (
     'abcd:' x 7 . 'abcd' => 'abcd:' x 7 . 'abcd',
-    '034:' x 7 . '034'   => '0034:' x 7 . '0034',
-    'abcd::'             => 'abcd:' . '0000:' x 6 . '0000',
-    '::abcd'             => '0000:' x 7 . 'abcd',
-    'abcd::034'          => 'abcd:' . '0000:' x 6 . '0034',
-    'abcd::192.168.1.1'  => 'abcd:' . '0000:' x 5 . 'c0a8:0101',
-    '::192.168.1.1'      => '0000:' x 6 . 'c0a8:0101',
-    '::'                 => '0000:' x 7 . '0000',
+    '034:' x 7 . '034'   => '34:' x 7 . '34',
+    'abcd::'             => 'abcd::',
+    '::abcd'             => '::abcd',
+    'abcd::034'          => 'abcd::34',
+    'abcd::192.168.1.1'  => 'abcd::c0a8:101',
+    '::192.168.1.1'      => '::c0a8:101',
+    '::'                 => '::',
+    '034:' x 7 . '034'   => '34:'x7 . '34',
 );
 
 diag "create a ticket via web and set IP" if $ENV{'TEST_VERBOSE'};
@@ -117,7 +118,6 @@ diag "create a ticket and edit IP field using Edit page"
 
     diag "set IP with spaces around" if $ENV{'TEST_VERBOSE'};
     my $new_ip    = '::3141';
-    my $new_value = '0000:' x 7 . '3141';
 
     $agent->follow_link_ok( { text => 'Basics', n => "1" },
         "Followed 'Basics' link" );
@@ -126,12 +126,12 @@ diag "create a ticket and edit IP field using Edit page"
     $agent->field( $cf_field => $new_ip );
     $agent->click('SubmitTicket');
 
-    $agent->content_contains( $new_value, "IP on the page" );
+    $agent->content_contains( $new_ip, "IP on the page" );
 
     $ticket = RT::Ticket->new($RT::SystemUser);
     $ticket->Load($id);
     ok( $ticket->id, 'loaded ticket' );
-    is( $ticket->FirstCustomFieldValue('IP'), $new_value, 'correct value' );
+    is( $ticket->FirstCustomFieldValue('IP'), $new_ip, 'correct value' );
 }
 
 diag "check that we parse correct IPs only" if $ENV{'TEST_VERBOSE'};
@@ -191,23 +191,19 @@ diag "create two tickets with different IPs and check several searches"
     $tickets = RT::Tickets->new($RT::SystemUser);
     $tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = 'abcd::'");
     is( $tickets->Count, 1, "found one ticket" );
-    is( $tickets->First->FirstCustomFieldValue('IP'),
-        'abcd' . ':0000' x 7, "correct value" );
+    is( $tickets->First->FirstCustomFieldValue('IP'), 'abcd::', "correct value" );
     $tickets = RT::Tickets->new($RT::SystemUser);
     $tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = 'bbcd::'");
     is( $tickets->Count, 1, "found one ticket" );
-    is( $tickets->First->FirstCustomFieldValue('IP'),
-        'bbcd' . ':0000' x 7, "correct value" );
+    is( $tickets->First->FirstCustomFieldValue('IP'), 'bbcd::', "correct value" );
 
     $tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} <= 'abcd::'");
     is( $tickets->Count, 1, "found one ticket" );
-    is( $tickets->First->FirstCustomFieldValue('IP'),
-        'abcd' . ':0000' x 7, "correct value" );
+    is( $tickets->First->FirstCustomFieldValue('IP'), 'abcd::', "correct value" );
     $tickets = RT::Tickets->new($RT::SystemUser);
     $tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} >= 'bbcd::'");
     is( $tickets->Count, 1, "found one ticket" );
-    is( $tickets->First->FirstCustomFieldValue('IP'),
-        'bbcd' . ':0000' x 7, "correct value" );
+    is( $tickets->First->FirstCustomFieldValue('IP'), 'bbcd::', "correct value" );
 
     $tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} > 'bbcd::'");
     is( $tickets->Count, 0, "no tickets found" );
@@ -217,12 +213,12 @@ diag "create two tickets with different IPs and check several searches"
     $tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} < 'bbcd::'");
     is( $tickets->Count, 1, "found one ticket" );
     is( $tickets->First->FirstCustomFieldValue('IP'),
-        'abcd' . ':0000' x 7, "correct value" );
+        'abcd::', "correct value" );
 
     $tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} > 'abcd::'");
     is( $tickets->Count, 1, "found one ticket" );
     is( $tickets->First->FirstCustomFieldValue('IP'),
-        'bbcd' . ':0000' x 7, "correct value" );
+        'bbcd::', "correct value" );
 }
 
 diag "create a ticket with an IP of abcd:23:: and search for doesn't match 'abcd:23'."

-----------------------------------------------------------------------


More information about the rt-commit mailing list