From 06791b06c4688b525c60dd90f2a7c81cf85e13f1 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 21 Nov 2019 11:57:16 +0100 Subject: [PATCH] Fix utils::EndsWith when needle bigger that value --- application/utils.inc.php | 5 +++++ test/application/UtilsTest.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/application/utils.inc.php b/application/utils.inc.php index 8a0488113..a4f7e0217 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -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; } diff --git a/test/application/UtilsTest.php b/test/application/UtilsTest.php index 50dee4142..a008eb53d 100644 --- a/test/application/UtilsTest.php +++ b/test/application/UtilsTest.php @@ -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 */