Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove bonus intval()

It caused issues when getting numeric keys that
exceeded PHP_INT_MAX.

Fixes #2897
  • Loading branch information...
commit 5270721adee6aa4b2d07a61f589f729092ab9632 1 parent c26df70
@markstory markstory authored
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
View
14 lib/Cake/Test/Case/Utility/SetTest.php
@@ -1658,6 +1658,20 @@ public function testClassicExtract() {
}
/**
+ * 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
*
* @return void
View
4 lib/Cake/Utility/Set.php
@@ -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

@lorenzo
Owner

Will this problem exist in Hash class too?

@markstory
Owner

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.
Something went wrong with that request. Please try again.