diff --git a/cake/libs/set.php b/cake/libs/set.php index e12c877d4..55b8c9f7a 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -383,9 +383,17 @@ class Set extends Object { * @access public */ function extract($path, $data = null, $options = array()) { + if (is_string($data) && $data{0} == '/') { + $tmp = $path; + $path = $data; + $data = $tmp; + } if (is_array($path) || empty($data) || is_object($path) || empty($path)) { return Set::classicExtract($path, $data); } + if ($path == '/') { + return $data; + } $contexts = $data; $options = am(array('flatten' => true), $options); if (!isset($contexts[0])) { diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index ffc6172c9..202a401d5 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -487,6 +487,13 @@ class SetTest extends UnitTestCase { $expected = array(1, 2, 4, 5); $r = Set::extract('/Comment[id!=3]/id', $common); $this->assertEqual($r, $expected); + + $r = Set::extract('/', $common); + $this->assertEqual($r, $common); + + $expected = array(1, 2, 4, 5); + $r = Set::extract($common, '/Comment[id!=3]/id'); + $this->assertEqual($r, $expected); } /** * undocumented function