Better support for regex matching, fixes #6184

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8086 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2009-03-10 20:20:32 +00:00
parent cb95f13608
commit 55e72bb749
2 changed files with 15 additions and 1 deletions

View file

@ -393,7 +393,7 @@ class Set extends Object {
do {
$token = array_shift($tokens);
$conditions = false;
if (preg_match_all('/\[([^\]]+)\]/', $token, $m)) {
if (preg_match_all('/\[([^=]+=\/[^\/]+\/|[^\]]+)\]/', $token, $m)) {
$conditions = $m[1];
$token = substr($token, 0, strpos($token, '['));
}

View file

@ -789,6 +789,20 @@ class SetTest extends CakeTestCase {
),
);
$r = Set::extract('/Comment/User[name=/\w+/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
$this->assertEqual($r[2]['Comment']['User']['name'], 'dan');
$this->assertEqual($r[3]['Comment']['User']['name'], 'dan');
$this->assertEqual(count($r), 4);
$r = Set::extract('/Comment/User[name=/[a-z]+/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'tod');
$this->assertEqual($r[2]['Comment']['User']['name'], 'dan');
$this->assertEqual($r[3]['Comment']['User']['name'], 'dan');
$this->assertEqual(count($r), 4);
$r = Set::extract('/Comment/User[name=/bob|dan/]/..', $habtm);
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
$this->assertEqual($r[1]['Comment']['User']['name'], 'dan');