Skip to content

Commit

Permalink
chg: Reject code that's less than 8 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
hangy committed Sep 11, 2023
1 parent 617c356 commit baf76d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ sub normalize_code ($code) {
if ((length($code) eq 13) and ($code =~ /^00000/)) {
$code = $';
}

if (length($code) < 8) {
$code = '';
}
}
return $code;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/products.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ is(normalize_code('https://example.com/01/00012345000058?17=271200'),
'0012345000058', 'should reduce GS1 Digital Link URI to GTIN');
is(normalize_code('https://world.openfoodfacts.org/'), '', 'non-GS1 URIs should return an empty string');
is(normalize_code('http://spam.zip/'), '', 'non-GS1 URIs should return an empty string');
is(normalize_code('http://spam.zip/42069'), '', 'non-GS1 URIs should return an empty string');
is(normalize_code('http://spam.zip/id/01/42069'), '', 'short should return an empty string');

# product storage path
is(product_path_from_id('not a real code'), 'invalid', 'non digit code should return "invalid"');
Expand Down

0 comments on commit baf76d5

Please sign in to comment.