Allowed for matching empty elements

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6875 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-15 02:21:51 +00:00
parent 673e0e6e6f
commit d039ad32d4
2 changed files with 8 additions and 2 deletions

View file

@ -515,7 +515,7 @@ class Set extends Object {
}
continue;
}
if (!preg_match('/(.+?)([><!]?[=]|[><])(.+)/', $condition, $match)) {
if (!preg_match('/(.+?)([><!]?[=]|[><])(.*)/', $condition, $match)) {
if (ctype_digit($condition)) {
if ($i != $condition) {
return false;
@ -532,7 +532,7 @@ class Set extends Object {
return false;
}
$val = $data[$key];
if ($op == '=' && $expected{0} == '/') {
if ($op == '=' && $expected && $expected{0} == '/') {
return preg_match($expected, $val);
} elseif ($op == '=' && $val != $expected) {
return false;

View file

@ -499,12 +499,14 @@ class SetTest extends UnitTestCase {
'user_id' => 2,
'article_id' => 2,
'text' => 'Comment 4',
'addition' => '',
),
array(
'id' => 5,
'user_id' => 23,
'article_id' => 2,
'text' => 'Comment 5',
'addition' => 'foo',
),
),
),
@ -559,6 +561,10 @@ class SetTest extends UnitTestCase {
$expected = array(3);
$r = Set::extract('/Article[:last]/id', $common);
$this->assertEqual($r, $expected);
$expected = array(array('Comment' => $common[1]['Comment'][0]));
$r = Set::extract('/Comment[addition=]', $common);
$this->assertEqual($r, $expected);
}
/**
* undocumented function