"Fixes #4001, 'money' validation uses invalid regular expression syntax"

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6605 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-03-26 06:44:40 +00:00
parent 1db7d00793
commit e65f44bed2
2 changed files with 29 additions and 2 deletions

View file

@ -577,10 +577,10 @@ class Validation extends Object {
$_this->check = $check;
switch ($symbolPosition) {
case 'left':
$_this->regex = '/^(?!\\u00a2)\\p{Sc}?(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?$/';
$_this->regex = '/^(?!\x{00a2})\p{Sc}?(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?$/u';
break;
case 'right':
$_this->regex = '/^(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?(?<!\\u00a2)\\p{Sc}?$/';
$_this->regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?<!\x{00a2})\p{Sc}?$/u';
break;
}
return $_this->_check();

View file

@ -1282,6 +1282,33 @@ class ValidationTestCase extends UnitTestCase {
$this->assertFalse(Validation::extension(array('noextension', 'extension.JPG', 'extension.gif', 'extension.png')));
$this->assertFalse(Validation::extension(array('extension.pdf', 'extension.JPG', 'extension.gif', 'extension.png')));
}
function testMoney() {
$this->assertTrue(Validation::money('$100'));
$this->assertTrue(Validation::money('$100.11'));
$this->assertTrue(Validation::money('$100.112'));
$this->assertFalse(Validation::money('$100.1'));
$this->assertFalse(Validation::money('$100.1111'));
$this->assertFalse(Validation::money('text'));
$this->assertTrue(Validation::money('100', 'right'));
$this->assertTrue(Validation::money('100.11$', 'right'));
$this->assertTrue(Validation::money('100.112$', 'right'));
$this->assertFalse(Validation::money('100.1$', 'right'));
$this->assertFalse(Validation::money('100.1111$', 'right'));
$this->assertTrue(Validation::money('€100'));
$this->assertTrue(Validation::money('€100.11'));
$this->assertTrue(Validation::money('€100.112'));
$this->assertFalse(Validation::money('€100.1'));
$this->assertFalse(Validation::money('€100.1111'));
$this->assertTrue(Validation::money('100', 'right'));
$this->assertTrue(Validation::money('100.11€', 'right'));
$this->assertTrue(Validation::money('100.112€', 'right'));
$this->assertFalse(Validation::money('100.1€', 'right'));
$this->assertFalse(Validation::money('100.1111€', 'right'));
}
/*
function TestFile() {
$this->assertTrue(Validation::file(WWW_ROOT . 'img' . DS . 'cake.icon.gif'));