summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-02-19 21:24:19 +0100
committerYorhel <git@yorhel.nl>2010-02-19 21:24:19 +0100
commit6423bc9f8b6c6283cbbc9b04954f63e7ad8ef1af (patch)
treefb380fe3f7a513d648f1561223c4de8788a4d72f /lib
parente5edd9736f065067172d56f394703f1062f5d743 (diff)
VNDB::Func: Another gtintype() related bugfix
We have to assume that the input doesn't always have enough zeros, to fill the 12 characters, otherwise UPC codes fail when they are fetched from the database (which is stored as a bigint, no zero padding in the output). Instead, we'll just add the zeros ourselves up to 12 for normalization purposes.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Func.pm5
-rw-r--r--lib/VNDB/Handler/Releases.pm1
2 files changed, 4 insertions, 2 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index d223d9f9..e00afe73 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -134,9 +134,10 @@ sub bb2html {
# Also 'normalizes' the first argument in place
sub gtintype {
$_[0] =~ s/[^\d]+//g;
+ $_[0] = ('0'x(12-length $_[0])) . $_[0] if length($_[0]) < 12; # pad with zeros to GTIN-12
my $c = shift;
- return undef if $c !~ /^[0-9]{12,13}$/; # only gtin-12 and 13
- $c = ('0'x(13-length $c)) . $c; # pad with zeros
+ return undef if $c !~ /^[0-9]{12,13}$/;
+ $c = "0$c" if length($c) == 12; # pad with another zero for GTIN-13
# calculate check digit according to
# http://www.gs1.org/productssolutions/barcodes/support/check_digit_calculator.html#how
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index 55bc9778..a0c860e2 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -295,6 +295,7 @@ sub edit {
sort { $a->{id} <=> $b->{id} } @{$r->{producers}}
),
);
+ gtintype($b4{gtin}); # normalize gtin code
$b4{vn} = join('|||', map "$_->{vid},$_->{title}", @$vn);
my $frm;