Skip to content

Commit

Permalink
Better support for regex matching, fixes #6184
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8086 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
felixge committed Mar 10, 2009
1 parent cb95f13 commit 55e72bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/set.php
Expand Up @@ -393,7 +393,7 @@ function extract($path, $data = null, $options = array()) {
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, '['));
}
Expand Down
14 changes: 14 additions & 0 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -789,6 +789,20 @@ function testExtract() {
),
);

$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');
Expand Down

0 comments on commit 55e72bb

Please sign in to comment.