Skip to content

Commit

Permalink
Remove bonus intval()
Browse files Browse the repository at this point in the history
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 5270721
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/Cake/Test/Case/Utility/SetTest.php
Expand Up @@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/Set.php
Expand Up @@ -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;
}
Expand Down

2 comments on commit 5270721

@lorenzo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this problem exist in Hash class too?

@markstory
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.