From 4a674e3bfa1708946c0fb490f2b66002da1f4a70 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 12 Jan 2025 18:36:30 +0100 Subject: [PATCH] Remove non-numeric characters when looking up OFF barcodes --- plugins/OpenFoodFactsBarcodeLookupPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/OpenFoodFactsBarcodeLookupPlugin.php b/plugins/OpenFoodFactsBarcodeLookupPlugin.php index 8ba8fe19..679e5f61 100644 --- a/plugins/OpenFoodFactsBarcodeLookupPlugin.php +++ b/plugins/OpenFoodFactsBarcodeLookupPlugin.php @@ -15,7 +15,7 @@ class OpenFoodFactsBarcodeLookupPlugin extends BaseBarcodeLookupPlugin protected function ExecuteLookup($barcode) { $webClient = new Client(['http_errors' => false]); - $response = $webClient->request('GET', "https://world.openfoodfacts.net/api/v2/product/$barcode?fields=product_name,image_url", ['headers' => ['User-Agent' => 'GrocyOpenFoodFactsBarcodeLookupPlugin/1.0 (https://grocy.info)']]); + $response = $webClient->request('GET', 'https://world.openfoodfacts.net/api/v2/product/' . preg_replace('/[^0-9]/', '', $barcode) . '?fields=product_name,image_url', ['headers' => ['User-Agent' => 'GrocyOpenFoodFactsBarcodeLookupPlugin/1.0 (https://grocy.info)']]); $statusCode = $response->getStatusCode(); // Guzzle throws exceptions for connection errors, so nothing to do on that here