From 55e72bb74966253da452d6f5f3f516fed31fe305 Mon Sep 17 00:00:00 2001 From: the_undefined Date: Tue, 10 Mar 2009 20:20:32 +0000 Subject: [PATCH] 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 --- cake/libs/set.php | 2 +- cake/tests/cases/libs/set.test.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cake/libs/set.php b/cake/libs/set.php index d4f6d9805..302056f98 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -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, '[')); } diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 75733a0b7..c1bf885dc 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -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');