From 74133f291538516d21f44be3f0a21a3e7e434b67 Mon Sep 17 00:00:00 2001
From: Steffen Kamper <info@sk-typo3.de>
Date: Thu, 12 Aug 2010 22:21:36 +0000
Subject: [PATCH] Fixed bug #3819: #15440: isFirstPartOfStr doesn't work with
 non-strings (Thanks to Michiel Roos)

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8594 709f56b5-9817-0410-a4d7-c38de5d9e867
---
 ChangeLog                     | 1 +
 t3lib/class.t3lib_div.php     | 8 ++------
 tests/t3lib/t3lib_divTest.php | 5 +++++
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 925b49b5be43..dc14ca215906 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
 
 2010-08-12 Steffen Kamper  <steffen@typo3.org>
 
+	* Fixed bug #3819: #15440: isFirstPartOfStr doesn't work with non-strings (Thanks to Michiel Roos)
 	* Follow-up to #3819: t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT') delivers wrong value in Backend
 	* Fixed bug #3819: t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT') delivers wrong value in Backend
 	* Fixed bug #15020: Enhancement of t3lib_div::testInt (Thanks to Michiel Roos)
diff --git a/t3lib/class.t3lib_div.php b/t3lib/class.t3lib_div.php
index e0b5407a24e6..eadcfbcf1acb 100644
--- a/t3lib/class.t3lib_div.php
+++ b/t3lib/class.t3lib_div.php
@@ -1290,12 +1290,8 @@ final class t3lib_div {
 	 * @param	string		Reference string which must be found as the "first part" of the full string
 	 * @return	boolean		True if $partStr was found to be equal to the first part of $str
 	 */
-	public static function isFirstPartOfStr($str,$partStr)	{
-		// Returns true, if the first part of a $str equals $partStr and $partStr is not ''
-		$psLen = strlen($partStr);
-		if ($psLen)	{
-			return substr($str,0,$psLen)==(string)$partStr;
-		} else return false;
+	public static function isFirstPartOfStr($str,$partStr) {
+		return $partStr != '' && strpos((string) $str, (string) $partStr, 0) === 0;
 	}
 
 	/**
diff --git a/tests/t3lib/t3lib_divTest.php b/tests/t3lib/t3lib_divTest.php
index 466902c97a53..c5e4fb1a7cab 100644
--- a/tests/t3lib/t3lib_divTest.php
+++ b/tests/t3lib/t3lib_divTest.php
@@ -164,6 +164,9 @@ class t3lib_divTest extends tx_phpunit_testcase {
 		return array(
 			'match first part of string' => array('hello world', 'hello'),
 			'match whole string' => array('hello', 'hello'),
+			'integer is part of string with same number' => array('24', 24),
+			'string is part of integer with same number' => array(24, '24'),
+			'integer is part of string starting with same number' => array('24 beer please', 24),
 		);
 	}
 
@@ -196,6 +199,8 @@ class t3lib_divTest extends tx_phpunit_testcase {
 			'empty string is not part of null' => array(NULL, ''),
 			'empty string is not part of false' => array(FALSE, ''),
 			'empty string is not part of zero integer' => array(0, ''),
+			'zero integer is not part of null' => array(NULL, 0),
+			'zero integer is not part of empty string' => array('', 0),
 		);
 	}
 
-- 
GitLab