Skip to content

Commit

Permalink
fix: warnings in import_convert_carrefour_france (#11189)
Browse files Browse the repository at this point in the history
### What

```
Error 1

    https://github.com/openfoodfacts/openfoodfacts-server/actions/runs/7462755789/job/20306470532?pr=9288#step:4:3088
    error: error parsing xml file with XML::Rules {error => "\nno element found at line 1, column 83, byte 83 at /opt/perl/local/lib/perl5/XML/Rules.pm line 745.\n",file => "tests/unit//inputs/import_convert_carrefour_france/13003_3270190006787_valNut.xml"}
    Use of uninitialized value in addition (+) at /opt/product-opener/lib/ProductOpener/ImportConvertCarrefourFrance.pm line 399.
    File tests/unit//inputs/import_convert_carrefour_france/13766_8431876196009_text.xml - Code: 8431876196009
    Reading file tests/unit//inputs/import_convert_carrefour_france/13766_8431876196009_text.xml
    Use of uninitialized value in concatenation (.) or string at /opt/product-opener/lib/ProductOpener/ImportConvertCarrefourFrance.pm line 160.
```

### Related issue(s) and discussion
- Related to #9655

---------

Co-authored-by: Open Food Facts Bot <[email protected]>
  • Loading branch information
benbenben2 and Open Food Facts Bot authored Jan 6, 2025
1 parent cbe221e commit 4643e3a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions lib/ProductOpener/ImportConvert.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ use Log::Any qw($log);
use Storable qw(dclone);
use Text::Fuzzy;

# to use read_file
use File::Slurp;

BEGIN {
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
@EXPORT_OK = qw(
Expand Down Expand Up @@ -1215,6 +1218,15 @@ sub load_xml_file ($file, $xml_rules_ref, $xml_fields_mapping_ref, $code) {

$log->info("parsing xml file with XML::Rules", {file => $file, xml_rules => $xml_rules_ref}) if $log->is_info();

# Read the file content
# Check if the file is empty or contains only comments
# See issue #9655, file 13003_3270190006787_valNut.xml + 5 others are empty
my $content = read_file($file);
if ($content =~ /^\s*<!--.*-->\s*$/s) {
# $log->warn("File is empty or contains only comments", {file => $file}) if $log->is_warn();
return 1;
}

my $parser = XML::Rules->new(rules => $xml_rules_ref);

my $xml_ref;
Expand Down
8 changes: 5 additions & 3 deletions lib/ProductOpener/ImportConvertCarrefourFrance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ sub convert_carrefour_france_files ($file_handle, $files_ref) {

#"b" => "pass",
#"strong" => "pass",
"b" => sub {return '<b>' . $_[1]->{_content} . '</b>'},
"strong" => sub {return '<strong>' . $_[1]->{_content} . '</strong>'},
"u" => sub {return '<u>' . $_[1]->{_content} . '</u>'},
"b" => sub {return '<b>' . ($_[1]->{_content} // '') . '</b>'},
"strong" => sub {return '<strong>' . ($_[1]->{_content} // '') . '</strong>'},
"u" => sub {return '<u>' . ($_[1]->{_content} // '') . '</u>'},
"em" => "pass",

"br" => "==<br />",
Expand Down Expand Up @@ -438,6 +438,8 @@ sub convert_carrefour_france_files ($file_handle, $files_ref) {
$product_ref->{producer_fr} = $product_ref->{emb_codes};
delete $product_ref->{emb_codes};
}

$product_ref->{lc} = "fr";
}

# Clean and normalize fields
Expand Down
5 changes: 4 additions & 1 deletion lib/ProductOpener/Ingredients.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3580,7 +3580,10 @@ reference to the name of the country
sub get_geographical_area ($originid) {
# Getting information about the country
my $ecobalyse_area = "";
if (get_inherited_property("countries", $originid, "ecobalyse_is_part_of_eu") eq "yes") {
my $ecobalyse_is_part_of_eu_result = get_inherited_property("countries", $originid, "ecobalyse_is_part_of_eu");
if (defined $ecobalyse_is_part_of_eu_result
&& $ecobalyse_is_part_of_eu_result eq "yes")
{
$ecobalyse_area = "eu";
}
if ($originid eq "en:france") {
Expand Down

0 comments on commit 4643e3a

Please sign in to comment.