mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
cb95f13608
commit
55e72bb749
2 changed files with 15 additions and 1 deletions
|
@ -393,7 +393,7 @@ class Set extends Object {
|
||||||
do {
|
do {
|
||||||
$token = array_shift($tokens);
|
$token = array_shift($tokens);
|
||||||
$conditions = false;
|
$conditions = false;
|
||||||
if (preg_match_all('/\[([^\]]+)\]/', $token, $m)) {
|
if (preg_match_all('/\[([^=]+=\/[^\/]+\/|[^\]]+)\]/', $token, $m)) {
|
||||||
$conditions = $m[1];
|
$conditions = $m[1];
|
||||||
$token = substr($token, 0, strpos($token, '['));
|
$token = substr($token, 0, strpos($token, '['));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
$r = Set::extract('/Comment/User[name=/bob|dan/]/..', $habtm);
|
||||||
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
|
$this->assertEqual($r[0]['Comment']['User']['name'], 'bob');
|
||||||
$this->assertEqual($r[1]['Comment']['User']['name'], 'dan');
|
$this->assertEqual($r[1]['Comment']['User']['name'], 'dan');
|
||||||
|
|
Loading…
Add table
Reference in a new issue