Skip to content

Commit

Permalink
N::P::UK parser (and data builder) fixed for 01768 88 mixed length st…
Browse files Browse the repository at this point in the history
…upidity
  • Loading branch information
DrHyde committed Jul 19, 2011
1 parent 1435f2b commit b50beca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,6 @@
XXXX-XX-XX 1.8003 UK parser made a teensy bit more robust; 2011-07-19 1.8003 UK parser made a teensy bit more robust;
UK parser bugfixed for 01768 88 mixed length stupidity
New UK allocations


2011-07-08 1.8002 New UK allocations; 2011-07-08 1.8002 New UK allocations;
Numerous small changes in Number::Phone::Country Numerous small changes in Number::Phone::Country
Expand Down
2 changes: 1 addition & 1 deletion build-data.realwork
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ foreach my $datum (@telco_length_data) {
warn "Empty format: $format (r: $retard; t: $telco)\n" warn "Empty format: $format (r: $retard; t: $telco)\n"
if($retard !~ /^[789]/); if($retard !~ /^[789]/);
} elsif($format eq 'Mixed 4+5 & 4+6') { } elsif($format eq 'Mixed 4+5 & 4+6') {
$format = '4+5 mixed'; $format = '4+5/6';
} elsif( } elsif(
$format ne '2+8' && $format ne '2+8' &&
$format ne '2+8' && $format ne '2+8' &&
Expand Down
4 changes: 3 additions & 1 deletion lib/Number/Phone/UK.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ sub is_valid {
$cache->{$number}->{format} = $Number::Phone::UK::Data::db->{telco_format}->{$telco_and_length}->{format}; $cache->{$number}->{format} = $Number::Phone::UK::Data::db->{telco_format}->{$telco_and_length}->{format};
if(defined($cache->{$number}->{format}) && $cache->{$number}->{format} =~ /\+/) { if(defined($cache->{$number}->{format}) && $cache->{$number}->{format} =~ /\+/) {
my($arealength, $subscriberlength) = split(/\+/, $cache->{$number}->{format}); my($arealength, $subscriberlength) = split(/\+/, $cache->{$number}->{format});
# for hateful mixed thing
my @subscriberlengths = ($subscriberlength =~ m{/}) ? split(/\//, $subscriberlength) : ($subscriberlength);
$subscriberlength =~ s/^(\d+).*/$1/; # for hateful mixed thing $subscriberlength =~ s/^(\d+).*/$1/; # for hateful mixed thing
$cache->{$number}->{areacode} = substr($parsed_number, 0, $arealength); $cache->{$number}->{areacode} = substr($parsed_number, 0, $arealength);
$cache->{$number}->{subscriber} = substr($parsed_number, $arealength); $cache->{$number}->{subscriber} = substr($parsed_number, $arealength);
Expand All @@ -111,7 +113,7 @@ sub is_valid {
$Number::Phone::UK::Data::db->{areanames}->{$_} $Number::Phone::UK::Data::db->{areanames}->{$_}
} grep { $Number::Phone::UK::Data::db->{areanames}->{$_} } @retards } grep { $Number::Phone::UK::Data::db->{areanames}->{$_} } @retards
)[0]; )[0];
if(length($cache->{$number}->{subscriber}) != $subscriberlength && $cache->{$number}->{format} !~ /mixed/i) { if(!grep { length($cache->{$number}->{subscriber}) == $_ } @subscriberlengths) {
# number wrong length! # number wrong length!
$cache->{$number} = undef; $cache->{$number} = undef;
return 0; return 0;
Expand Down
Binary file modified lib/Number/Phone/UK/Data.pm
Binary file not shown.
22 changes: 17 additions & 5 deletions t/01_uk_data.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use strict;


use Number::Phone::UK; use Number::Phone::UK;


BEGIN { $| = 1; print "1..68\n"; } BEGIN { $| = 1; print "1..73\n"; }


my $test = 0; my $test = 0;


Expand Down Expand Up @@ -151,12 +151,24 @@ print 'ok '.(++$test)." 03 numbers are formatted right\n";
print 'not ' unless(Number::Phone->new('+44169772200')->format() eq print 'not ' unless(Number::Phone->new('+44169772200')->format() eq
'+44 16977 2200'); '+44 16977 2200');
print 'ok '.(++$test)." 5+4 format works\n"; print 'ok '.(++$test)." 5+4 format works\n";
print 'not ' unless(Number::Phone->new('+44176888000')->format() eq
'+44 1768 88000'); # 01768 88 is "Mixed 4+5 & 4+6". I wish someone would just set the village on fire.
print 'not ' unless(Number::Phone->new('+44 1768 88 000')->format() eq '+44 1768 88000'); # 4+5
print 'ok '.(++$test)." 4+5 (mixed) format works\n";
print 'not ' unless(Number::Phone->new('+44 1768 88 100')->format() eq '+44 1768 88100');
print 'ok '.(++$test)." 4+5 (mixed) format works\n"; print 'ok '.(++$test)." 4+5 (mixed) format works\n";
print 'not ' unless(Number::Phone->new('+441768881000')->format() eq
'+44 1768 881000'); print 'not ' unless(Number::Phone->new('+44 1768 88 0000')->format() eq '+44 1768 880000'); # 4+6
print 'ok '.(++$test)." 4+6 (mixed) format works\n"; print 'ok '.(++$test)." 4+6 (mixed) format works\n";
print 'not ' unless(Number::Phone->new('+44 1768 88 1000')->format() eq '+44 1768 881000');
print 'ok '.(++$test)." 4+6 (mixed) format works\n";

print 'not ' if(Number::Phone->new('+44 1768 88 0')); # 4+3
print 'ok '.(++$test)." 4+3 in that range correctly fails\n";
print 'not ' if(Number::Phone->new('+44 1768 88 00')); # 4+4
print 'ok '.(++$test)." 4+4 in that range correctly fails\n";
print 'not ' if(Number::Phone->new('+44 1768 88 00000')); # 4+7
print 'ok '.(++$test)." 4+7 in that range correctly fails\n";


$number = Number::Phone->new('+447400000000'); $number = Number::Phone->new('+447400000000');
print 'not ' unless($number->is_mobile()); print 'not ' unless($number->is_mobile());
Expand Down

0 comments on commit b50beca

Please sign in to comment.