浏览代码

Merge pull request #232 from challgren/fix-casting-common

Fixing issue where ints are casted to strings
Mark Sch 6 年之前
父节点
当前提交
ba379f8672
共有 2 个文件被更改,包括 21 次插入5 次删除
  1. 7 3
      src/Utility/Utility.php
  2. 14 2
      tests/TestCase/Utility/UtilityTest.php

+ 7 - 3
src/Utility/Utility.php

@@ -439,9 +439,9 @@ class Utility {
 	/**
 	/**
 	 * Trim recursively
 	 * Trim recursively
 	 *
 	 *
-	 * @param string|array|null $value
+	 * @param mixed $value
 	 * @param bool $transformNullToString
 	 * @param bool $transformNullToString
-	 * @return array|string
+	 * @return mixed
 	 */
 	 */
 	public static function trimDeep($value, $transformNullToString = false) {
 	public static function trimDeep($value, $transformNullToString = false) {
 		if (is_array($value)) {
 		if (is_array($value)) {
@@ -451,7 +451,11 @@ class Utility {
 			return $value;
 			return $value;
 		}
 		}
 
 
-		return ($value === null && !$transformNullToString) ? $value : trim($value);
+		if (is_string($value) || $value === null) {
+			return ($value === null && !$transformNullToString) ? $value : trim($value);
+		}
+
+		return $value;
 	}
 	}
 
 
 	/**
 	/**

+ 14 - 2
tests/TestCase/Utility/UtilityTest.php

@@ -337,12 +337,24 @@ class UtilityTest extends TestCase {
 		$is = [
 		$is = [
 			'f some',
 			'f some',
 			'e 49r ' => 'rf r ',
 			'e 49r ' => 'rf r ',
-			'er' => [['ee' => ['rr ' => ' tt ', 'empty' => null]]]
+			'er' => [['ee' => ['rr ' => ' tt ', 'empty' => null]]],
+			'bsh' => 1,
+			'bkd' => '1',
+			'bol' => true,
+			'bl' => 'true',
+			'flt' => 3.14,
+			'fl' => '3.14'
 		];
 		];
 		$expected = [
 		$expected = [
 			'f some',
 			'f some',
 			'e 49r ' => 'rf r',
 			'e 49r ' => 'rf r',
-			'er' => [['ee' => ['rr ' => 'tt', 'empty' => null]]]
+			'er' => [['ee' => ['rr ' => 'tt', 'empty' => null]]],
+			'bsh' => 1,
+			'bkd' => '1',
+			'bol' => true,
+			'bl' => 'true',
+			'flt' => 3.14,
+			'fl' => '3.14'
 		];
 		];
 
 
 		$res = Utility::trimDeep($is);
 		$res = Utility::trimDeep($is);