Optimize product name special characters handling in OFF external barcode lookup plugin

This commit is contained in:
Bernd Bestel
2025-03-04 20:38:10 +01:00
parent 63dcfcde47
commit 46253c455f
2 changed files with 63 additions and 1 deletions

View File

@@ -52,11 +52,14 @@ class OpenFoodFactsBarcodeLookupPlugin extends BaseBarcodeLookupPlugin
// Use the localized product name, if provided
$name = $data->product->product_name;
if (isset($data->product->$productNameFieldLocalized))
if (isset($data->product->$productNameFieldLocalized) && !empty($data->product->$productNameFieldLocalized))
{
$name = $data->product->$productNameFieldLocalized;
}
// Remove non-ASCII characters in product name (whyever a product name should have them at all)
$name = preg_replace('/[^\x20-\x7E]/', '', $name);
return [
'name' => $name,
'location_id' => $locationId,