Skip to content

Commit 0eaf97e

Browse files
webmaster777Naktibalda
authored andcommitted
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 e0aa26c commit 0eaf97e

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
@@ -3553,8 +3553,12 @@ protected function getRelativeTabHandle($offset)
35533553

35543554
$handle = $this->webDriver->getWindowHandle();
35553555
$handles = $this->webDriver->getWindowHandles();
3556-
$idx = array_search($handle, $handles);
3557-
return $handles[($idx + $offset) % count($handles)];
3556+
$currentHandleIdx = array_search($handle, $handles);
3557+
$newHandleIdx = ($currentHandleIdx + $offset) % count($handles);
3558+
if ($newHandleIdx < 0) {
3559+
$newHandleIdx = count($handles) + $newHandleIdx;
3560+
}
3561+
return $handles[$newHandleIdx];
35583562
}
35593563

35603564
/**

0 commit comments

Comments
 (0)