Skip to content
Snippets Groups Projects
Commit 42fc890a authored by Russell Bryant's avatar Russell Bryant
Browse files

The behavior of REGEX when it did not match was not defined by the docs, so

define it to provide a result of "0" and change the code appropriately.
(issue #7805)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@41544 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 6557d250
Branches
Tags
No related merge requests found
...@@ -115,7 +115,7 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf, ...@@ -115,7 +115,7 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf,
int errcode; int errcode;
regex_t regexbuf; regex_t regexbuf;
buf[0] = '\0'; buf[0] = '0';
AST_NONSTANDARD_APP_ARGS(args, parse, '"'); AST_NONSTANDARD_APP_ARGS(args, parse, '"');
...@@ -130,10 +130,10 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf, ...@@ -130,10 +130,10 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf,
regerror(errcode, &regexbuf, buf, len); regerror(errcode, &regexbuf, buf, len);
ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf); ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf);
return -1; return -1;
} else {
if (!regexec(&regexbuf, args.str, 0, NULL, 0))
strcpy(buf, "1");
} }
strcpy(buf, regexec(&regexbuf, args.str, 0, NULL, 0) ? "0" : "1");
regfree(&regexbuf); regfree(&regexbuf);
return 0; return 0;
...@@ -141,8 +141,8 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf, ...@@ -141,8 +141,8 @@ static int regex(struct ast_channel *chan, char *cmd, char *parse, char *buf,
static struct ast_custom_function regex_function = { static struct ast_custom_function regex_function = {
.name = "REGEX", .name = "REGEX",
.synopsis = .synopsis = "Regular Expression",
"Regular Expression: Returns 1 if data matches regular expression.", .desc = "Returns 1 if data matches regular expression, or 0 otherwise.",
.syntax = "REGEX(\"<regular expression>\" <data>)", .syntax = "REGEX(\"<regular expression>\" <data>)",
.read = regex, .read = regex,
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment