{
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
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.)
--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"
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