[Home]

Summary:ASTERISK-07654: Function REGEX fails to match beginning of string
Reporter:hristo (hristo)Labels:
Date Opened:2006-09-01 09:20:42Date Closed:2006-09-08 11:51:31
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Core/Configuration
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:If you try to match the beginnig of a string with REGEX function (latest trunk) it will return 0 instead of 1.

How to reproduce:
exten => 1234,1,NoOp(${REGEX("^ab" abc)})

and the output is:
[Sep  1 17:16:36] DEBUG[23951]: func_strings.c:127 regex: FUNCTION REGEX (^ab)( abc)
[Sep  1 17:16:36] DEBUG[23951]: pbx.c:1537 pbx_substitute_variables_helper_full: Function result is '0'

Note: I have also tried to backslash both " and ^ but I get the same result.

****** ADDITIONAL INFORMATION ******

The same regex expression works as expected and returns 1 when tested against the latest svn-1.2
Comments:By: hristo (hristo) 2006-09-06 12:34:37

I believe I have found the problem. It should be trivial to fix.
After parsing, the begining of the string contains a leading space, that's why it is not matched by the expression. Btw, this is also visible in the DEBUG output above.

By: Steve Murphy (murf) 2006-09-06 23:27:40

Yes, you spotted the problem. But you were invited by the documentation for this function, to make this error! I have committed a small fix to the doc strings for this func, that removes the space after the double quotes in the syntax, and explicitly warns users not to include unnecessary spaces in that region. Hopefully, this will help the countless thousands in the future, that might have  the same problem as you did. See r.  42224.

By: Steve Murphy (murf) 2006-09-06 23:30:16

Hopefully, hristo will indeed verify that removing the space solves the problem. If not, hristo, please reopen this and we will investigate further.

By: hristo (hristo) 2006-09-07 03:54:16

Removing the space indeed fixes the problem. Actually, that's how I've figured out the problem is in the leading space in the first place. However, for the sake of backwards compatibility with 1.2 configurations and for better readability maybe it's still better to leave the space after the quotes and to remove it within the code before the regex is run against the string. This shold make the life of all upgrading users a little bit easier.
If this is not acceptable, please, ignore this note and close the issue.

By: Steve Murphy (murf) 2006-09-08 11:51:31

hristo, you have made a good point. I missed the fact that the space was part of 1.2.x behavior. So, I've just checked in another fix to func_strings.c (42423) with this message:

"As per discussion on bug 7862, the problem wasn't the fact that the documentation differed from behavior, but rather that users are used to REGEX having that space after the double quote in 1.2.x. So, in keeping with history, I investigated a little deeper, and discovered that the change in behavior was due to the modification of the function to use the AST_DECLARE_APP_ARGS and AST_NONSTANDARD_APP_ARGS() to parse the args. The code to skip the blank was left out. So, what I did was add code to throw out the first blank (space or tab) after the double quote, IF IT IS THERE. If not, nothing is done.Verbage is added to the function description saying that the space is optional, and skipped if it is there. If a space is desired, then the documentation advises putting two spaces there. This should make it compatible for 1.2 users, and not mess up new users who are used to using it with no space. It WILL mess up new users who WANT a space. Hopefully, they will double check the doc strings for this func and add the extra space. Hopefully, this class of new user is very small."

Reopen this bug (again) if rev 42423 of func_strings.c, where REGEX is defined, does not behave properly. I tested it against a set of patterns, and it looked OK to me...