Skip to content

Commit fcd2bf1

Browse files
committed
fix: more precise checks after webdriver response deserialization
1 parent c9c994d commit fcd2bf1

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/Client/W3CClient.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ function (ResponseInterface $response) use ($tabLookupDeferred) {
277277
try {
278278
$tabIdentifiers = $this->deserializeResponse($response);
279279

280+
if (!is_array($tabIdentifiers)) {
281+
throw new RuntimeException('Unable to locate tab identifiers in the response.');
282+
}
283+
280284
$tabLookupDeferred->resolve($tabIdentifiers);
281285
} catch (Throwable $exception) {
282286
$reason = new RuntimeException(
@@ -323,6 +327,10 @@ public function getActiveTabIdentifier(string $sessionIdentifier): PromiseInterf
323327
function (ResponseInterface $response) {
324328
$tabIdentifier = $this->deserializeResponse($response);
325329

330+
if (!is_string($tabIdentifier)) {
331+
throw new RuntimeException('Unable to locate a tab identifier in the response.');
332+
}
333+
326334
return $tabIdentifier;
327335
}
328336
)
@@ -438,6 +446,10 @@ public function getCurrentUri(string $sessionIdentifier): PromiseInterface
438446
function (ResponseInterface $response) {
439447
$uriCurrent = $this->deserializeResponse($response);
440448

449+
if (!is_string($uriCurrent)) {
450+
throw new RuntimeException('Unable to locate an URI in the response.');
451+
}
452+
441453
return $uriCurrent;
442454
}
443455
)
@@ -475,6 +487,10 @@ public function getSource(string $sessionIdentifier): PromiseInterface
475487
function (ResponseInterface $response) {
476488
$sourceCode = $this->deserializeResponse($response);
477489

490+
if (!is_string($sourceCode)) {
491+
throw new RuntimeException('Unable to locate source code in the response.');
492+
}
493+
478494
return $sourceCode;
479495
}
480496
)
@@ -599,6 +615,10 @@ public function getElementVisibility(string $sessionIdentifier, array $elementId
599615
function (ResponseInterface $response) {
600616
$visibilityStatus = $this->deserializeResponse($response);
601617

618+
if (!is_bool($visibilityStatus)) {
619+
throw new RuntimeException('Unable to locate a visibility status in the response.');
620+
}
621+
602622
return $visibilityStatus;
603623
}
604624
)
@@ -778,7 +798,12 @@ public function getScreenshot(string $sessionIdentifier): PromiseInterface
778798
->then(
779799
function (ResponseInterface $response) {
780800
$imageContentsEncoded = $this->deserializeResponse($response);
781-
$imageContents = base64_decode($imageContentsEncoded);
801+
802+
if (!is_string($imageContentsEncoded)) {
803+
throw new RuntimeException('Unable to locate screenshot contents in the response.');
804+
}
805+
806+
$imageContents = base64_decode($imageContentsEncoded);
782807

783808
return $imageContents;
784809
}

0 commit comments

Comments
 (0)