Skip to content

Commit

Permalink
fix: broken CSV (#2426) (#7318)
Browse files Browse the repository at this point in the history
Fix broken CSV (#2426)

Should solve #2426. Script not tested, in itself, but I have done some successful tests with:
`perl -ne 'print if /(\xE2\x80\xA8|\xE2\x80\xA9|[\000-\007\013-\037])/' en.openfoodfacts.org.products.csv`

I suggest to control in production.
  • Loading branch information
CharlesNepote authored Sep 7, 2022
1 parent c49176e commit 4c62929
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/export_database.pl
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,20 @@ ($)
# VT (013), FF (014 or \f), CR (015 or \r), etc.
# See https://en.wikipedia.org/wiki/ASCII
#
# Also replace UTF-8 Line Separator (U+2028) and Paragraph Separator (U+2029):
# \xE2\x80\xA8 and \xE2\x80\xA9
#
# TODO? put it in ProductOpener::Data & use it to control data input and output
# Q: Do we have to *always* delete \n?
# TODO? Send an email if bad-chars?
sub sanitize_field_content {
my $content = (shift(@_) // "");
my $LOG = shift(@_);
my $log_msg = (shift(@_) // "");
if ($content =~ /[\000-\037]/) {
if ($content =~ /(\xE2\x80\xA8|\xE2\x80\xA9|[\000-\037])/) {
print $LOG "$log_msg $content\n\n---\n" if (defined $LOG);
# TODO? replace the bad char by a space or by nothing?
$content =~ s/[\000-\037]+/ /g;
$content =~ s/(\xE2\x80\xA8|\xE2\x80\xA9|[\000-\037])+/ /g;
};
return $content;
}
Expand Down

0 comments on commit 4c62929

Please sign in to comment.