Skip to content

Commit 22e15dd

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 baa18b7 commit 22e15dd

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
@@ -3503,8 +3503,12 @@ protected function getRelativeTabHandle($offset)
35033503
}
35043504
$handle = $this->webDriver->getWindowHandle();
35053505
$handles = $this->webDriver->getWindowHandles();
3506-
$idx = array_search($handle, $handles);
3507-
return $handles[($idx + $offset) % count($handles)];
3506+
$currentHandleIdx = array_search($handle, $handles);
3507+
$newHandleIdx = ($currentHandleIdx + $offset) % count($handles);
3508+
if ($newHandleIdx < 0) {
3509+
$newHandleIdx = count($handles) + $newHandleIdx;
3510+
}
3511+
return $handles[$newHandleIdx];
35083512
}
35093513

35103514
/**

0 commit comments

Comments
 (0)