From 46253c455f21abad44385c725cd31f3368715428 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Tue, 4 Mar 2025 20:38:10 +0100 Subject: [PATCH] Optimize product name special characters handling in OFF external barcode lookup plugin --- changelog/80_UNRELEASED_xxxx-xx-xx.md | 59 ++++++++++++++++++++ plugins/OpenFoodFactsBarcodeLookupPlugin.php | 5 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 changelog/80_UNRELEASED_xxxx-xx-xx.md diff --git a/changelog/80_UNRELEASED_xxxx-xx-xx.md b/changelog/80_UNRELEASED_xxxx-xx-xx.md new file mode 100644 index 00000000..cbd5db7f --- /dev/null +++ b/changelog/80_UNRELEASED_xxxx-xx-xx.md @@ -0,0 +1,59 @@ +> ⚠️ xxxBREAKING CHANGESxxx + +> ❗ xxxImportant upgrade informationXXX + +> 💡 xxxMinor upgrade informationXXX + +### New Feature: xxxx + +- xxx + +### Stock + +- Optimizations in the built-in Open Food Facts external barcode lookup plugin: + - A provided but empty localized product name is now ignored + - Non-ASCII characters in product names are now ignored (e.g. line breaks caused problems) + +### Shopping list + +- xxx + +### Recipes + +- xxx + +### Meal plan + +- xxx + +### Chores + +- xxx + +### Calendar + +- xxx + +### Tasks + +- xxx + +### Batteries + +- xxx + +### Equipment + +- xxx + +### Userfields + +- xxx + +### General + +- xxx + +### API + +- xxx diff --git a/plugins/OpenFoodFactsBarcodeLookupPlugin.php b/plugins/OpenFoodFactsBarcodeLookupPlugin.php index 46d16510..8730740a 100644 --- a/plugins/OpenFoodFactsBarcodeLookupPlugin.php +++ b/plugins/OpenFoodFactsBarcodeLookupPlugin.php @@ -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,