From fa4ee3e3ecb39097c0dedc8003bde90b125dc6f1 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Tue, 19 Mar 2024 20:15:15 -0700 Subject: [PATCH] CLI-1293: [api:notifications:find] typeerror for sketchy notification strings (#1705) * CLI-1293: [api:notifications:find] typeerror for sketchy notification strings * add test * mutation test --- src/Command/CommandBase.php | 9 +++++++-- tests/phpunit/src/Commands/App/TaskWaitCommandTest.php | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index af5c8b7d1..44245b439 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -1233,9 +1233,14 @@ private static function getNotificationUuid(string $notification): string { // Not a UUID, maybe a JSON object? try { $json = json_decode($notification, NULL, 4, JSON_THROW_ON_ERROR); - return CommandBase::getNotificationUuidFromResponse($json); + if (is_object($json)) { + return self::getNotificationUuidFromResponse($json); + } + // In rare cases, JSON can decode to a string that's a valid UUID. + self::validateUuid($json); + return $json; } - catch (JsonException | AcquiaCliException) { + catch (JsonException | AcquiaCliException | ValidatorException) { } // Last chance, maybe a URL? diff --git a/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php b/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php index 05f5c22b7..03525a3cd 100644 --- a/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php +++ b/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php @@ -84,6 +84,9 @@ public function providerTestTaskWaitCommand(): array { } EOT, ], + [ + '"1bd3487e-71d1-4fca-a2d9-5f969b3d35c1"', + ], ]; } @@ -148,6 +151,9 @@ public function providerTestTaskWaitCommandWithInvalidJson(): array { } EOT, ], + [ + '"11bd3487e-71d1-4fca-a2d9-5f969b3d35c1"', + ], ]; }