From 2a3e23ded468bf4544bac359a1a6c08cd10ae7a3 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Tue, 4 Mar 2025 20:40:48 +0100 Subject: [PATCH] Handle image URLs with query parameters returned from an external barcode lookup plugin --- changelog/80_UNRELEASED_xxxx-xx-xx.md | 1 + services/StockService.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog/80_UNRELEASED_xxxx-xx-xx.md b/changelog/80_UNRELEASED_xxxx-xx-xx.md index cbd5db7f..29a4c8f0 100644 --- a/changelog/80_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/80_UNRELEASED_xxxx-xx-xx.md @@ -13,6 +13,7 @@ - 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) +- Optimized that when an external barcode lookup plugin returned an image URL with query parameters, an invalid picture (file name) was added to the created product ### Shopping list diff --git a/services/StockService.php b/services/StockService.php index 2261db4e..70f2cf24 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -626,7 +626,7 @@ class StockService extends BaseService { $webClient = new Client(); $response = $webClient->request('GET', $pluginOutput['__image_url'], ['headers' => ['User-Agent' => 'Grocy/' . $this->getApplicationService()->GetInstalledVersion()->Version . ' (https://grocy.info)']]); - $fileName = $pluginOutput['__barcode'] . '.' . pathinfo($pluginOutput['__image_url'], PATHINFO_EXTENSION); + $fileName = $pluginOutput['__barcode'] . '.' . pathinfo(parse_url($pluginOutput['__image_url'], PHP_URL_PATH), PATHINFO_EXTENSION); file_put_contents($this->getFilesService()->GetFilePath('productpictures', $fileName), $response->getBody()); $productData['picture_file_name'] = $fileName; }