nette / utils

🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
https://doc.nette.org/utils
Other
1.98k stars 147 forks source link

Strings::indexOf() ends with ValueError for empty $haystack for negative $nth #271

Closed KacerCZ closed 2 years ago

KacerCZ commented 2 years ago

Version: 3.2.5 PHP: 8.0.12

Bug Description

Calling method Strings::indexOf() with parameter $haystack being empty string and negative parameter $nth will end with ValueError "strrpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)".

Steps To Reproduce

Execute following code

$position = \Nette\Utils\Strings::indexOf( '', 'a', -1 );
var_dump( $position );

ValueError is thrown

Expected Behavior

Variable $position contains NULL.