Permalink
Browse files

Remove bonus intval()

It caused issues when getting numeric keys that
exceeded PHP_INT_MAX.

Fixes #2897
  • Loading branch information...
markstory committed May 23, 2012
1 parent c26df70 commit 5270721adee6aa4b2d07a61f589f729092ab9632
Showing with 16 additions and 2 deletions.
  1. +14 −0 lib/Cake/Test/Case/Utility/SetTest.php
  2. +2 −2 lib/Cake/Utility/Set.php
@@ -1657,6 +1657,20 @@ public function testClassicExtract() {
$this->assertEquals($expected, $result);
}
+/**
+ * test classicExtract with keys that exceed 32bit max int.
+ *
+ * @return void
+ */
+ public function testClassicExtractMaxInt() {
+ $data = array(
+ 'Data' => array(
+ '13376924712' => 'abc'
+ )
+ );
+ $this->assertEquals('abc', Set::classicExtract($data, 'Data.13376924712'));
+ }
+
/**
* testInsert method
*
View
@@ -603,8 +603,8 @@ public static function classicExtract($data, $path = null) {
foreach ($path as $i => $key) {
if (is_numeric($key) && intval($key) > 0 || $key === '0') {
- if (isset($data[intval($key)])) {
- $data = $data[intval($key)];
+ if (isset($data[$key])) {
+ $data = $data[$key];
} else {
return null;
}

2 comments on commit 5270721

Owner

lorenzo replied May 23, 2012

Will this problem exist in Hash class too?

Owner

markstory replied May 23, 2012

I looked for intval() there and the only one was in insert() / remove(). So the same problem shouldn't exist unless people do insert()/remove() with big ints.

Please sign in to comment.