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

@@ -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

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,