From 5a19a56a45e35f0cf5cab4e3ddd771b695e0b8e4 Mon Sep 17 00:00:00 2001 From: Sebastian Almberg <83243306+Sebbeben@users.noreply.github.com> Date: Sun, 8 Feb 2026 10:46:53 +0100 Subject: [PATCH] Fix 304 response body, parse_url safety, and location/stock consistency - Use empty Response instead of JsonResponse(null) for 304 Not Modified to avoid sending "null" as response body - Guard parse_url() result with is_string() since it can return false for malformed URLs - Move storage location tracking inside the availability check so expired and unknown-quantity lots don't contribute locations --- src/Controller/KiCadApiController.php | 2 +- src/Services/EDA/KiCadHelper.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Controller/KiCadApiController.php b/src/Controller/KiCadApiController.php index 2cfa9b0e..a5d5eecd 100644 --- a/src/Controller/KiCadApiController.php +++ b/src/Controller/KiCadApiController.php @@ -97,7 +97,7 @@ class KiCadApiController extends AbstractController $etag = '"' . md5(json_encode($data)) . '"'; if ($request->headers->get('If-None-Match') === $etag) { - return new JsonResponse(null, Response::HTTP_NOT_MODIFIED); + return new Response('', Response::HTTP_NOT_MODIFIED); } $response = new JsonResponse($data); diff --git a/src/Services/EDA/KiCadHelper.php b/src/Services/EDA/KiCadHelper.php index 48af4219..37b94f33 100644 --- a/src/Services/EDA/KiCadHelper.php +++ b/src/Services/EDA/KiCadHelper.php @@ -294,15 +294,16 @@ class KiCadHelper } } - //Add stock quantity and storage locations + //Add stock quantity and storage locations (only count non-expired lots with known quantity) $totalStock = 0; $locations = []; foreach ($part->getPartLots() as $lot) { - if (!$lot->isInstockUnknown() && $lot->isExpired() !== true) { + $isAvailable = !$lot->isInstockUnknown() && $lot->isExpired() !== true; + if ($isAvailable) { $totalStock += $lot->getAmount(); - } - if ($lot->getAmount() > 0 && $lot->getStorageLocation() !== null) { - $locations[] = $lot->getStorageLocation()->getName(); + if ($lot->getAmount() > 0 && $lot->getStorageLocation() !== null) { + $locations[] = $lot->getStorageLocation()->getName(); + } } } $result['fields']['Stock'] = $this->createField($totalStock); @@ -443,8 +444,8 @@ class KiCadHelper if ($firstPdf === null) { $extension = $attachment->getExtension(); if ($extension === null && $attachment->hasExternal()) { - $urlPath = parse_url($attachment->getExternalPath(), PHP_URL_PATH) ?? ''; - $extension = strtolower(pathinfo($urlPath, PATHINFO_EXTENSION)); + $urlPath = parse_url($attachment->getExternalPath(), PHP_URL_PATH); + $extension = is_string($urlPath) ? strtolower(pathinfo($urlPath, PATHINFO_EXTENSION)) : null; } if ($extension === 'pdf') { $firstPdf = $attachment;