From d527e375bce7a43036b2b25f57eb459828cfdb7a Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Thu, 26 Sep 2024 16:02:39 +0200 Subject: [PATCH] NTR: fix tracking code (#846) Co-authored-by: Vitalij Mik --- src/Service/TrackingInfoStructFactory.php | 2 +- src/Service/UrlParsingService.php | 2 +- tests/PHPUnit/Service/UrlParsingServiceTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Service/TrackingInfoStructFactory.php b/src/Service/TrackingInfoStructFactory.php index 33dede484..5d4b75dcc 100644 --- a/src/Service/TrackingInfoStructFactory.php +++ b/src/Service/TrackingInfoStructFactory.php @@ -120,7 +120,7 @@ private function createInfoStruct(string $trackingCarrier, string $trackingCode, ]); // determine if the provided tracking code is actually a tracking URL - if (empty($trackingUrl) === true || $this->urlParsingService->isUrl($trackingCode)) { + if (empty($trackingUrl) === true && $this->urlParsingService->isUrl($trackingCode)) { $this->logger->debug('Tracking code is a URL, parsing tracking code from URL.', [ 'trackingCode' => $trackingCode, 'trackingUrl' => $trackingUrl diff --git a/src/Service/UrlParsingService.php b/src/Service/UrlParsingService.php index 5eec41974..59fe47bdc 100644 --- a/src/Service/UrlParsingService.php +++ b/src/Service/UrlParsingService.php @@ -36,7 +36,7 @@ public function parseTrackingCodeFromUrl(string $value): array $urlQuery = parse_url($value, PHP_URL_FRAGMENT); } if ($urlQuery === null) { - return ['', $value]; + return [$value,'']; } $urlQuery = (string)$urlQuery; $urlWithoutQuery = str_replace($urlQuery, '', $value); diff --git a/tests/PHPUnit/Service/UrlParsingServiceTest.php b/tests/PHPUnit/Service/UrlParsingServiceTest.php index b5c2d8daf..4a7434db7 100644 --- a/tests/PHPUnit/Service/UrlParsingServiceTest.php +++ b/tests/PHPUnit/Service/UrlParsingServiceTest.php @@ -82,8 +82,8 @@ public function testParseTrackingCodeNotFound(string $input, array $expected) public function notFoundProvider(): array { return [ - ['https://www.example.com/product', ['', 'https://www.example.com/product']], - ['https://www.example.com/code/product', ['', 'https://www.example.com/code/product']], + ['https://www.example.com/product', ['https://www.example.com/product','']], + ['https://www.example.com/code/product', ['https://www.example.com/code/product','']], ]; }