Skip Menu |

This queue is for tickets about the Geo-Postcode CPAN distribution.

Report information
The Basics
Id: 16956
Status: resolved
Priority: 0/
Queue: Geo-Postcode

People
Owner: Nobody in particular
Requestors: philip [...] zaynar.demon.co.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.15
Fixed in: (no value)



Subject: [PATCH] Valid postcodes containing '0' considered invalid
Geo::Postcode's 'valid' tests "$a && $d && $s && $u". For real postcodes like "N20 0AD", $s eq "0", which is false, so 'valid' thinks the postcode is invalid. The attached patch changes 'valid' and 'valid_fragment' to test definedness instead of truth. It also, unrelatedly, fixes a use-of-uninitialised-variable warning in calls to 'location_class'. Thanks, Philip (@zaynar.demon.co.uk)
--- Postcode.pm.old 2006-01-07 20:49:46.000000000 +0000 +++ Postcode.pm 2006-01-07 21:01:28.000000000 +0000 @@ -163,7 +163,7 @@ sub location_class { my $self = shift; my $class = shift; - if (defined $class && $class ne $self->{location_class}) { + if (defined $class && (!defined $self->{location_class} || $class ne $self->{location_class})) { $self->{location} = undef; return $self->{location_class} = $class; } @@ -305,7 +305,7 @@ return $self if $self->_special_case; my ($a, $d, $s, $u) = @{ $self->fragments }; - return unless $a && $d && $s && $u; + return unless defined $a && defined $d && defined $s && defined $u; return if length($a) > 2; return if $a =~ /[\W\d]/; return if $a =~ /^[QVX]/; @@ -332,20 +332,20 @@ return 1 if $self->_special_case; my ($a, $d, $s, $u) = @{ $self->fragments }; - return unless $a; + return unless defined $a; return if length($a) > 2; return if $a =~ /[\W\d]/; return if $a =~ /^[QVX]/; return if $a =~ /^.[IJZ]/; - return 1 unless $d || $s || $u; + return 1 unless defined $d || defined $s || defined $u; return if length($a) == 1 && $d !~ /\d[\dABCDEFGHJKSTUW]?/; return if length($a) == 2 && $d !~ /\d[\dABEHMNPRVWXY]?/; - return 1 unless $s || $u; + return 1 unless defined $s || defined $u; return if length($s) > 1; return if $s =~ /\D/; - return 1 unless $u; + return 1 unless defined $u; return if length($u) != 2; return if $u =~ /[^A-Z]/;
[guest - Sat Jan 7 17:14:15 2006]: Show quoted text
> Geo::Postcode's 'valid' tests "$a && $d && $s && $u". For real > postcodes like "N20 0AD", $s eq "0", which is false, so 'valid' thinks > the postcode is invalid. > > The attached patch changes 'valid' and 'valid_fragment' to test > definedness instead of truth. It also, unrelatedly, fixes a use-of- > uninitialised-variable warning in calls to 'location_class'. > > Thanks, > Philip (@zaynar.demon.co.uk)
thanks very much. I had already caught this one - so I'm sorry about the trouble you've gone to - but work on GP has been a bit held up by a friendly but rather firm discussion with the post office. The next version I upload has to be without the sample data (which was gathered by jibble.org, but they decided not to put up a fight), and so I have to work out how to make it useful out of the box. it shouldn't be more than a week or two now. best will
From: llap [...] cuckoo.org
On Sat Jan 07 17:14:15 2006, guest wrote: Show quoted text
> Geo::Postcode's 'valid' tests "$a && $d && $s && $u". For real > postcodes like "N20 0AD", $s eq "0", which is false, so 'valid' thinks > the postcode is invalid. > > The attached patch changes 'valid' and 'valid_fragment' to test > definedness instead of truth. It also, unrelatedly, fixes a use-of- > uninitialised-variable warning in calls to 'location_class'.
Bits of this applied (didn't need "defined" on _everything_) Heading to cpan now as 0.17 Sneak peak from: https://github.com/ranguard/Geo- Postcode/commit/5b077c76288ae33d855082d3a8bee299fb29129b