Skip to content

Commit

Permalink
fix: normalize code for /products endpoint openfoodfacts#6024 (openfo…
Browse files Browse the repository at this point in the history
…odfacts#6026) (#1234)

Co-authored-by: Stéphane Gigandet <stephane@openfoodfacts.org>
  • Loading branch information
pull[bot] and stephanegigandet committed Oct 27, 2021
1 parent 2fceabc commit 3cafb22
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4609,11 +4609,24 @@ sub add_params_to_query($$) {
# xyz=a|b xyz=a,b xyz=a+b products with either xyz a or xyz b

if ($values =~ /\||\+|,/) {
# Multiple values: construct a MongoDB $in query
my @values = split(/\||\+|,/, $values);
$query_ref->{$field} = { '$in' => \@values };
if ($field eq "code") {
# normalize barcodes: add missing leading 0s
$query_ref->{$field} = { '$in' => [ map { normalize_code($_) } @values ] };
}
else {
$query_ref->{$field} = { '$in' => \@values };
}
}
else {
$query_ref->{$field} = $values;
# Single value
if ($field eq "code") {
$query_ref->{$field} = normalize_code($values);
}
else {
$query_ref->{$field} = $values;
}
}
}
}
Expand Down

0 comments on commit 3cafb22

Please sign in to comment.