From 52c6884e28a68dac89b862d42f5c0b4a807a5aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 17 Jul 2023 23:21:30 +0200 Subject: [PATCH] Allow slashes in digikey product ids --- src/Controller/PartController.php | 2 +- src/Services/InfoProviderSystem/PartInfoRetriever.php | 11 +++++++++-- .../InfoProviderSystem/Providers/DigikeyProvider.php | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 5b80a5cb..3adfda5c 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -220,7 +220,7 @@ class PartController extends AbstractController return $this->renderPartForm('new', $request, $new_part); } - #[Route('/from_info_provider/{providerKey}/{providerId}/create', name: 'info_providers_create_part')] + #[Route('/from_info_provider/{providerKey}/{providerId}/create', name: 'info_providers_create_part', requirements: ['providerId' => '.+'])] public function createFromInfoProvider(Request $request, string $providerKey, string $providerId, PartInfoRetriever $infoRetriever): Response { $this->denyAccessUnlessGranted('@info_providers.create_parts'); diff --git a/src/Services/InfoProviderSystem/PartInfoRetriever.php b/src/Services/InfoProviderSystem/PartInfoRetriever.php index f9bf4d84..744610f7 100644 --- a/src/Services/InfoProviderSystem/PartInfoRetriever.php +++ b/src/Services/InfoProviderSystem/PartInfoRetriever.php @@ -73,7 +73,10 @@ final class PartInfoRetriever */ protected function searchInProvider(InfoProviderInterface $provider, string $keyword): array { - return $this->partInfoCache->get("search_{$provider->getProviderKey()}_{$keyword}", function (ItemInterface $item) use ($provider, $keyword) { + //Generate key and escape reserved characters from the provider id + $escaped_keyword = urlencode($keyword); + + return $this->partInfoCache->get("search_{$provider->getProviderKey()}_{$escaped_keyword}", function (ItemInterface $item) use ($provider, $keyword) { //Set the expiration time $item->expiresAfter(self::CACHE_RESULT_EXPIRATION); @@ -92,7 +95,11 @@ final class PartInfoRetriever { $provider = $this->provider_registry->getProviderByKey($provider_key); - return $this->partInfoCache->get("details_{$provider_key}_{$part_id}", function (ItemInterface $item) use ($provider, $part_id) { + //Generate key and escape reserved characters from the provider id + $escaped_part_id = urlencode($part_id); + + + return $this->partInfoCache->get("details_{$provider_key}_{$escaped_part_id}", function (ItemInterface $item) use ($provider, $part_id) { //Set the expiration time $item->expiresAfter(self::CACHE_DETAIL_EXPIRATION); diff --git a/src/Services/InfoProviderSystem/Providers/DigikeyProvider.php b/src/Services/InfoProviderSystem/Providers/DigikeyProvider.php index f85db0aa..31b9cb41 100644 --- a/src/Services/InfoProviderSystem/Providers/DigikeyProvider.php +++ b/src/Services/InfoProviderSystem/Providers/DigikeyProvider.php @@ -135,7 +135,7 @@ class DigikeyProvider implements InfoProviderInterface public function getDetails(string $id): PartDetailDTO { - $response = $this->digikeyClient->request('GET', '/Search/v3/Products/' . $id, [ + $response = $this->digikeyClient->request('GET', '/Search/v3/Products/' . urlencode($id), [ 'auth_bearer' => $this->authTokenManager->getAlwaysValidTokenString(self::OAUTH_APP_NAME) ]);