Skip to content

Commit

Permalink
Merge pull request #3914 from openfoodfacts/short-barcodes
Browse files Browse the repository at this point in the history
fix for short barcodes
  • Loading branch information
stephanegigandet authored Jul 22, 2020
2 parents 2e3a4e1 + 9df43cf commit f62ffba
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cgi/product_jqm_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

$code = normalize_code($code);

if ($code !~ /^\d{8,24}$/) {
if ($code !~ /^\d{4,24}$/) {

$log->info("invalid code", { code => $code, original_code => $original_code }) if $log->is_info();
$response{status} = 0;
Expand Down
4 changes: 2 additions & 2 deletions cgi/product_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
if ((not defined $code) or ($code eq "")) {
$code = process_search_image_form(\$filename);
}
elsif ($code !~ /^\d{8,24}$/) {
elsif ($code !~ /^\d{4,24}$/) {
display_error($Lang{invalid_barcode}{$lang}, 403);
}

Expand Down Expand Up @@ -173,7 +173,7 @@
if ((not defined $code) or ($code eq '')) {
display_error($Lang{missing_barcode}{$lang}, 403);
}
elsif ($code !~ /^\d{8,24}$/) {
elsif ($code !~ /^\d{4,24}$/) {
display_error($Lang{invalid_barcode}{$lang}, 403);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion cgi/search.pl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
if ((not defined param('json')) and (not defined param('jsonp')) and
(not defined param('jqm')) and (not defined param('jqm_loadmore')) and
(not defined param('xml')) and (not defined param('rss')) and
($search_terms =~ /^(\d{8,24})$/)) {
($search_terms =~ /^(\d{4,24})$/)) {

my $code = normalize_code($search_terms);

Expand Down
5 changes: 3 additions & 2 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4233,6 +4233,7 @@ sub search_and_display_products($$$$$) {
}
}
}

}

elsif (defined $product_ref->{$field}) {
Expand Down Expand Up @@ -7279,7 +7280,7 @@ sub display_product($)
my $code = normalize_code($request_code);
local $log->context->{code} = $code;
if ($code !~ /^\d{8,24}$/) {
if ($code !~ /^\d{4,24}$/) {
display_error($Lang{invalid_barcode}{$lang}, 403);
}
Expand Down Expand Up @@ -9774,7 +9775,7 @@ sub display_product_api($)
$response{code} = $code;
my $product_ref = retrieve_product($product_id);
if ($code !~ /^\d{8,24}$/) {
if ($code !~ /^\d{4,24}$/) {
$log->info("invalid code", { code => $code, original_code => $request_ref->{code} }) if $log->is_info();
$response{status} = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ sub change_product_server_or_code($$$) {
}

$new_code = normalize_code($new_code);
if ($new_code !~ /^\d{8,24}$/) {
if ($new_code !~ /^\d{4,24}$/) {
display_error($Lang{invalid_barcode}{$lang}, 403);
}
else {
Expand Down

0 comments on commit f62ffba

Please sign in to comment.