Allow character classes in attribute patterns.

Fixes #3706
This commit is contained in:
mark_story 2013-03-14 12:55:03 -04:00
parent 60f9131940
commit 246c09ae40
2 changed files with 5 additions and 1 deletions

View file

@ -873,6 +873,10 @@ class HashTest extends CakeTestCase {
$result = Hash::extract($data, '{n}.Article[title=/^First/]');
$expected = array($data[0]['Article']);
$this->assertEquals($expected, $result);
$result = Hash::extract($data, '{n}.Article[title=/^Fir[a-z]+/]');
$expected = array($data[0]['Article']);
$this->assertEquals($expected, $result);
}
/**

View file

@ -170,7 +170,7 @@ class Hash {
*/
protected static function _matches(array $data, $selector) {
preg_match_all(
'/(\[ (?<attr>[^=><!]+?) (\s* (?<op>[><!]?[=]|[><]) \s* (?<val>[^\]]+) )? \])/x',
'/(\[ (?<attr>[^=><!]+?) (\s* (?<op>[><!]?[=]|[><]) \s* (?<val>(?:\/.*?\/ | [^\]]+)) )? \])/x',
$selector,
$conditions,
PREG_SET_ORDER