mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixed bug in parent traversal, closes #5225
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7546 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
2deb6f3828
commit
95947053fe
2 changed files with 57 additions and 1 deletions
|
@ -397,7 +397,8 @@ class Set extends Object {
|
|||
$context = array('trace' => array(), 'item' => $context, 'key' => null);
|
||||
}
|
||||
if ($token == '..') {
|
||||
$context['item'] = Set::extract(join('/', $context['trace']), $data);
|
||||
$parent = join('/', $context['trace']).'['.($key+1).']';
|
||||
$context['item'] = Set::extract($parent, $data);
|
||||
$context['key'] = array_pop($context['trace']);
|
||||
$context['item'] = $context['item'][0][$context['key']];
|
||||
$matches[] = $context;
|
||||
|
|
|
@ -633,6 +633,61 @@ class SetTest extends CakeTestCase {
|
|||
$expected = array(array('Comment' => $common[1]['Comment'][0]));
|
||||
$r = Set::extract('/Comment[addition=]', $common);
|
||||
$this->assertEqual($r, $expected);
|
||||
|
||||
$habtm = array(
|
||||
array(
|
||||
'Post' => array(
|
||||
'id' => 1,
|
||||
'title' => 'great post',
|
||||
),
|
||||
'Comment' => array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'text' => 'foo',
|
||||
'User' => array(
|
||||
'id' => 1,
|
||||
'name' => 'bob'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'text' => 'bar',
|
||||
'User' => array(
|
||||
'id' => 2,
|
||||
'name' => 'tod'
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'Post' => array(
|
||||
'id' => 2,
|
||||
'title' => 'fun post',
|
||||
),
|
||||
'Comment' => array(
|
||||
array(
|
||||
'id' => 3,
|
||||
'text' => '123',
|
||||
'User' => array(
|
||||
'id' => 3,
|
||||
'name' => 'dan'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'text' => '987',
|
||||
'User' => array(
|
||||
'id' => 4,
|
||||
'name' => 'jim'
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
$r = Set::extract('/Comment/User[name=/bob|dan/]/..', $habtm);
|
||||
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
|
||||
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
|
||||
$this->assertEqual(count($r), 2);
|
||||
}
|
||||
/**
|
||||
* testMatches method
|
||||
|
|
Loading…
Reference in a new issue