com php-src: Add option to specific the expected separator character.: ext/filter/logical_filters.c ext/filter/tests/055 .phpt
| From: | Martin Jansen | Date: | Sun, 03 Feb 2013 12:23:54 +0000 |
| Subject: | com php-src: Add option to specific the expected separator character.: ext/filter/logical_filters.c ext/filter/tests/055 .phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-71154@lists.php.net to get a copy of this message | ||
Commit: 6186b676000f74af92b979382f605ed104b6a4bc
Author: Martin Jansen <martin@divbyzero.net> Sat, 5 Jan 2013 22:46:14 +0100
Parents: 0661d03ebaab6cf1eff156a4dd203299d0385ae9
Branches: PHP-5.5 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6186b676000f74af92b979382f605ed104b6a4bc
Log:
Add option to specific the expected separator character.
Changed paths:
M ext/filter/logical_filters.c
M ext/filter/tests/055.phpt
Diff:
diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c
index fededcf..9b436a7 100644
--- a/ext/filter/logical_filters.c
+++ b/ext/filter/logical_filters.c
@@ -788,9 +788,18 @@ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
{
char *input = Z_STRVAL_P(value);
int input_len = Z_STRLEN_P(value);
- int tokens, length, i, offset;
+ int tokens, length, i, offset, exp_separator_set, exp_separator_len;
char separator;
+ char *exp_separator;
long ret = 0;
+ zval **option_val;
+
+ FETCH_STRING_OPTION(exp_separator, "separator");
+
+ if (exp_separator_set && exp_separator_len != 1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Separator must be exactly one character
long");
+ RETURN_VALIDATION_FAILED;
+ }
if (14 == input_len) {
/* EUI-64 format: Four hexadecimal digits separated by dots. Less
@@ -813,6 +822,10 @@ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
RETURN_VALIDATION_FAILED;
}
+ if (exp_separator_set && separator != exp_separator[0]) {
+ RETURN_VALIDATION_FAILED;
+ }
+
/* Essentially what we now have is a set of tokens each consisting of
* a hexadecimal number followed by a separator character. (With the
* exception of the last token which does not have the separator.)
diff --git a/ext/filter/tests/055.phpt b/ext/filter/tests/055.phpt
index bf94f35..688dbb2 100644
--- a/ext/filter/tests/055.phpt
+++ b/ext/filter/tests/055.phpt
@@ -5,24 +5,32 @@ filter_var() and FILTER_VALIDATE_MAC
--FILE--
<?php
$values = Array(
- "01-23-45-67-89-ab",
- "01-23-45-67-89-AB",
- "01-23-45-67-89-aB",
- "01:23:45:67:89:ab",
- "01:23:45:67:89:AB",
- "01:23:45:67:89:aB",
- "01:23:45-67:89:aB",
- "xx:23:45:67:89:aB",
- "0123.4567.89ab",
+ array("01-23-45-67-89-ab", null),
+ array("01-23-45-67-89-ab", array("options" => array("separator"
=> "-"))),
+ array("01-23-45-67-89-ab", array("options" => array("separator"
=> "."))),
+ array("01-23-45-67-89-ab", array("options" => array("separator"
=> ":"))),
+ array("01-23-45-67-89-AB", null),
+ array("01-23-45-67-89-aB", null),
+ array("01:23:45:67:89:ab", null),
+ array("01:23:45:67:89:AB", null),
+ array("01:23:45:67:89:aB", null),
+ array("01:23:45-67:89:aB", null),
+ array("xx:23:45:67:89:aB", null),
+ array("0123.4567.89ab", null),
+ array("01-23-45-67-89-ab", array("options" => array("separator"
=> "--"))),
+ array("01-23-45-67-89-ab", array("options" => array("separator"
=> ""))),
);
foreach ($values as $value) {
- var_dump(filter_var($value, FILTER_VALIDATE_MAC));
+ var_dump(filter_var($value[0], FILTER_VALIDATE_MAC, $value[1]));
}
echo "Done\n";
?>
---EXPECT--
+--EXPECTF--
string(17) "01-23-45-67-89-ab"
+string(17) "01-23-45-67-89-ab"
+bool(false)
+bool(false)
string(17) "01-23-45-67-89-AB"
string(17) "01-23-45-67-89-aB"
string(17) "01:23:45:67:89:ab"
@@ -31,4 +39,10 @@ string(17) "01:23:45:67:89:aB"
bool(false)
bool(false)
string(14) "0123.4567.89ab"
+
+Warning: filter_var(): Separator must be exactly one character long in %s055.php on line %d
+bool(false)
+
+Warning: filter_var(): Separator must be exactly one character long in %s055.php on line %d
+bool(false)
Done