From e65f44bed24ca7a2d5811cb7ce53c891a0fda9ba Mon Sep 17 00:00:00 2001 From: phpnut Date: Wed, 26 Mar 2008 06:44:40 +0000 Subject: [PATCH] "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 --- cake/libs/validation.php | 4 ++-- cake/tests/cases/libs/validation.test.php | 27 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cake/libs/validation.php b/cake/libs/validation.php index 13f1e2c8a..eb2a3f83e 100644 --- a/cake/libs/validation.php +++ b/cake/libs/validation.php @@ -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})?(?regex = '/^(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{2})?(?_check(); diff --git a/cake/tests/cases/libs/validation.test.php b/cake/tests/cases/libs/validation.test.php index 0cba3af5d..738fb73a7 100644 --- a/cake/tests/cases/libs/validation.test.php +++ b/cake/tests/cases/libs/validation.test.php @@ -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'));