Changeset 964
- Timestamp:
- 10/21/07 18:12:03 (9 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/service/jsonrpc/stubJsonRpcProcessor.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/util/validators/stubRegexValidator.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessor.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/integration/ValidatorsXJConfTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotationTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/util/validators/stubRegexValidatorTestCase.php (modified) (4 diffs)
- trunk/src/test/resources/xjconf/validators.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/service/jsonrpc/stubJsonRpcProcessor.php
r955 r964 29 29 * Regexp to validate method param 30 30 */ 31 const CLASS_AND_METHOD_PATTERN = ' ^([a-zA-Z0-9_]+\.[a-zA-Z0-9_]+)$';31 const CLASS_AND_METHOD_PATTERN = '/^([a-zA-Z0-9_]+\.[a-zA-Z0-9_]+)$/'; 32 32 /** 33 33 * Regexp to validate param param 34 34 */ 35 const PARAM_PATTERN = ' ^[a-zA-Z0-9_]+$';35 const PARAM_PATTERN = '/^[a-zA-Z0-9_]+$/'; 36 36 /** 37 37 * Regexp to validate id param 38 38 */ 39 const ID_PATTERN = ' ^\d{6,7}$';39 const ID_PATTERN = '/^\d{6,7}$/'; 40 40 /** 41 41 * Registry key for the service config file … … 79 79 80 80 if ($this->request->hasValue('__generateProxy')) { 81 $proxyClassvalidator = new stubRegexValidator(' ^[A-Za-z,0-9_\.]+$');81 $proxyClassvalidator = new stubRegexValidator('/^[A-Za-z,0-9_\.]+$/'); 82 82 $classes = $this->request->getValidatedValue($proxyClassvalidator, '__generateProxy', stubRequest::SOURCE_PARAM); 83 83 if ($classes === '__all') { … … 87 87 } 88 88 } elseif ($this->request->hasValue('__smd')) { 89 $smdClassvalidator = new stubRegexValidator(' ^[A-Za-z0-9_\.]+$');89 $smdClassvalidator = new stubRegexValidator('/^[A-Za-z0-9_\.]+$/'); 90 90 $class = $this->request->getValidatedValue($smdClassvalidator, '__smd', stubRequest::SOURCE_PARAM); 91 91 $this->generateSmd($class); … … 304 304 { 305 305 if ($className === null) { 306 if (!preg_match( '/'.self::CLASS_AND_METHOD_PATTERN.'/', $methodName)) {306 if (!preg_match(self::CLASS_AND_METHOD_PATTERN, $methodName)) { 307 307 throw new stubException('Invalid request: method-Pattern has to be <className>.<methodName>.'); 308 308 } trunk/src/main/php/net/stubbles/util/validators/stubRegexValidator.php
r731 r964 12 12 * 13 13 * The validator uses preg_match() and checks if the value occurs exactly 14 * one time. Please note that a delimiter is automatically applied. The used15 * delimiter is /, therefore it must be escaped if this character is part of16 * the regular expression.14 * one time. Please make sure that the supplied regular expresion contains 15 * correct delimiters, they will not be applied automatically. The validate() 16 * method throws a runtime exception in case the regular expression is invalid. 17 17 * 18 18 * @package stubbles … … 30 30 /** 31 31 * constructor 32 *33 * Please note that a delimiter is automatically applied. The used34 * delimiter is /, therefore it must be escaped if this character35 * is part of the regular expression.36 32 * 37 33 * @param string $regex regular expression to use for validation … … 57 53 * @param mixed $value 58 54 * @return bool true if value complies with regular expression, else false 55 * @throws stubRuntimeException in case the used regular expresion is invalid 59 56 */ 60 57 public function validate($value) 61 58 { 62 if (preg_match('/' . $this->regex . '/', $value) != 1) { 63 return false; 59 $check = @preg_match($this->regex, $value); 60 if (false === $check) { 61 throw new stubRuntimeException('Invalid regular expression ' . $this->regex); 64 62 } 65 66 return true;63 64 return ((1 != $check) ? (false) : (true)); 67 65 } 68 66 trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessor.php
r799 r964 124 124 125 125 if ($this->request->hasValue('page') == true) { 126 $pageName = $this->request->getValidatedValue(new stubRegexValidator(' ([a-zA-Z0-9_])'), 'page');126 $pageName = $this->request->getValidatedValue(new stubRegexValidator('/([a-zA-Z0-9_])/'), 'page'); 127 127 if (null == $pageName || $this->pageFactory->hasPage($dirPrefix . $pageName) == false) { 128 128 $pageName = 'index'; trunk/src/test/php/net/stubbles/integration/ValidatorsXJConfTestCase.php
r959 r964 129 129 $regexValidator = $this->xjconf->getConfigValue('regex'); 130 130 $this->assertIsA($regexValidator, 'stubRegexValidator'); 131 $this->assertEqual($regexValidator->getCriteria(), array('regex' => ' ([a-Z]){1,3}'));131 $this->assertEqual($regexValidator->getCriteria(), array('regex' => '/([a-Z]){1,3}/')); 132 132 } 133 133 trunk/src/test/php/net/stubbles/ipo/request/broker/annotations/stubStringFilterAnnotationTestCase.php
r736 r964 51 51 $this->stringFilterAnnotation->setMinLength(1); 52 52 $this->stringFilterAnnotation->setMaxLength(2); 53 $this->stringFilterAnnotation->setRegex(' foo');53 $this->stringFilterAnnotation->setRegex('/foo/'); 54 54 $stringFilter = $this->stringFilterAnnotation->getFilter(); 55 55 $this->assertIsA($stringFilter, 'stubStringFilter'); … … 59 59 $this->assertEqual($stringFilter->getMaxLengthValidator()->getValue(), 2); 60 60 $this->assertIsA($stringFilter->getRegexValidator(), 'stubRegexValidator'); 61 $this->assertEqual($stringFilter->getRegexValidator()->getValue(), ' foo');61 $this->assertEqual($stringFilter->getRegexValidator()->getValue(), '/foo/'); 62 62 } 63 63 trunk/src/test/php/net/stubbles/util/validators/stubRegexValidatorTestCase.php
r696 r964 1 1 <?php 2 2 /** 3 * Tests for net.stubbles.util.validators.stubRegexValidator 3 * Tests for net.stubbles.util.validators.stubRegexValidator. 4 4 * 5 * @author Frank Kleine < frank@kl-s.com>5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 7 * @subpackage util_validators_test … … 9 9 stubClassLoader::load('net.stubbles.util.validators.stubRegexValidator'); 10 10 /** 11 * Tests for net.stubbles.util.validators.stubRegexValidator 11 * Tests for net.stubbles.util.validators.stubRegexValidator. 12 12 * 13 13 * @package stubbles … … 29 29 { 30 30 // regex allows only three lowercase characters 31 $this->regexValidator = new stubRegexValidator(' ^([a-z]{3})$');31 $this->regexValidator = new stubRegexValidator('/^([a-z]{3})$/'); 32 32 } 33 33 … … 44 44 45 45 /** 46 * assure that validation using modifiers in regular expression works correct 47 */ 48 public function testValidationWithModifier() 49 { 50 $regexValidator = new stubRegexValidator('/^([a-z]{3})$/i'); 51 $this->assertTrue($regexValidator->validate('foo')); 52 $this->assertTrue($regexValidator->validate('Bar')); 53 $this->assertFalse($regexValidator->validate('baz0123')); 54 $this->assertFalse($regexValidator->validate(null)); 55 } 56 57 /** 58 * assert that a runtime exception is thrown in case an invalid regular 59 * expression is used 60 */ 61 public function testInvalidRegex() 62 { 63 $regexValidator = new stubRegexValidator('^([a-z]{3})$'); 64 $this->expectException('stubRuntimeException'); 65 $regexValidator->validate('foo'); 66 } 67 68 /** 46 69 * assure that returning the criterias works correct 47 70 */ 48 71 public function testGetCriteria() 49 72 { 50 $this->assertEqual($this->regexValidator->getCriteria(), array('regex' => ' ^([a-z]{3})$'));73 $this->assertEqual($this->regexValidator->getCriteria(), array('regex' => '/^([a-z]{3})$/')); 51 74 } 52 75 } trunk/src/test/resources/xjconf/validators.xml
r959 r964 18 18 </values> 19 19 </preSelect> 20 <regex setterMethod="regex"> ([a-Z]){1,3}</regex>20 <regex setterMethod="regex">/([a-Z]){1,3}/</regex> 21 21 22 22 <and setterMethod="and">
