Fix utils::EndsWith when needle bigger that value

This commit is contained in:
Pierre Goiffon
2019-11-21 11:57:16 +01:00
parent 5ebc290b94
commit 06791b06c4
2 changed files with 10 additions and 0 deletions

View File

@@ -2097,6 +2097,11 @@ class utils
* @return bool
*/
final public static function EndsWith($haystack, $needle) {
if (strlen($needle) > strlen($haystack))
{
return false;
}
return substr_compare($haystack, $needle, -strlen($needle)) === 0;
}

View File

@@ -33,6 +33,11 @@ class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
require_once(APPROOT.'application/utils.inc.php');
}
public function testEndsWith()
{
$this->assertFalse(utils::EndsWith('a', 'bbbb'));
}
/**
* @dataProvider memoryLimitDataProvider
*/