Skip to content

Commit 65d5003

Browse files
committed
prevent negative array-offset getting
The modulo operation can result in a negative number, while the list of window handles is always a 0-based array
1 parent 3a0cb1c commit 65d5003

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Codeception/Module/WebDriver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,8 +3575,12 @@ protected function getRelativeTabHandle($offset)
35753575

35763576
$handle = $this->webDriver->getWindowHandle();
35773577
$handles = $this->webDriver->getWindowHandles();
3578-
$idx = array_search($handle, $handles);
3579-
return $handles[($idx + $offset) % count($handles)];
3578+
$currentHandleIdx = array_search($handle, $handles);
3579+
$newHandleIdx = ($currentHandleIdx + $offset) % count($handles);
3580+
if ($newHandleIdx < 0) {
3581+
$newHandleIdx = count($handles) + $newHandleIdx;
3582+
}
3583+
return $handles[$newHandleIdx];
35803584
}
35813585

35823586
/**

0 commit comments

Comments
 (0)