Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not accept whitespace by default in "Alnum" rule
The "Alnum" rule is supposed to validate alphanumeric values, but instead, it also validates any whitespace character as valid. The rule also accepts a list of characters on its constructor, so it the users intentionally want some specific characters to also be allowed it is better than they also defined these characters on the rule's constructor. While refactoring the rule I could notice that "AbstractCtypeRule" is just an overhead that does not add much to it, so instead of extending it "Alnum" now extends "AbstractFilterRule" directly (which is the parent of "AbstractCtypeRule"). And since we want all rules to follow our contribution guidelines, this commit also make sure the "Alnum" rule is in accordance with that. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
- Loading branch information
1 parent
fb9d3a6
commit 779c0c1
Showing
13 changed files
with
156 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--FILE-- | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
use Respect\Validation\Exceptions\AlnumException; | ||
use Respect\Validation\Exceptions\NestedValidationException; | ||
use Respect\Validation\Validator as v; | ||
|
||
try { | ||
v::alnum()->check('abc%1'); | ||
} catch (AlnumException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::alnum(' ')->check('abc%2'); | ||
} catch (AlnumException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::alnum())->check('abcd3'); | ||
} catch (AlnumException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::alnum('% '))->check('abc%4'); | ||
} catch (AlnumException $exception) { | ||
echo $exception->getMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::alnum()->assert('abc^1'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::alnum())->assert('abcd2'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::alnum('* &%')->assert('abc^3'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
|
||
try { | ||
v::not(v::alnum('^'))->assert('abc^4'); | ||
} catch (NestedValidationException $exception) { | ||
echo $exception->getFullMessage().PHP_EOL; | ||
} | ||
?> | ||
--EXPECTF-- | ||
"abc%1" must contain only letters (a-z) and digits (0-9) | ||
"abc%2" must contain only letters (a-z), digits (0-9) and " " | ||
"abcd3" must not contain letters (a-z) or digits (0-9) | ||
"abc%4" must not contain letters (a-z), digits (0-9) or "% " | ||
- "abc^1" must contain only letters (a-z) and digits (0-9) | ||
- "abcd2" must not contain letters (a-z) or digits (0-9) | ||
- "abc^3" must contain only letters (a-z), digits (0-9) and "* &%" | ||
- "abc^4" must not contain letters (a-z), digits (0-9) or "^" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.