Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6354] isMatch adaptive expression returns error when value is null or empty string #6426

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions libraries/AdaptiveExpressions/BuiltinFunctions/IsMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,11 @@ private static EvaluateExpressionDelegate Evaluator()
return FunctionUtils.ApplyWithError(
args =>
{
var value = false;
string error = null;
var regex = CommonRegex.CreateRegex(args[1].ToString());
var inputString = args[0]?.ToString() ?? string.Empty;
var value = regex.IsMatch(inputString);

string inputString = args[0]?.ToString();
if (string.IsNullOrEmpty(inputString))
{
value = false;
error = "regular expression is empty.";
}
else
{
var regex = CommonRegex.CreateRegex(args[1].ToString());
value = regex.IsMatch(inputString);
}

return (value, error);
return (value, null);
}, FunctionUtils.VerifyStringOrNull);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ public class ExpressionParserTests
Test(@"isMatch('1', '\\d{1}')", true), // "\d" (match [0-9])
Test(@"isMatch('12.5', '[0-9]+(\\.5)')", true), // "\." (match .)
Test(@"isMatch('12x5', '[0-9]+(\\.5)')", false), // "\." (match .)
Test("isMatch('', '([0-9])')", false), // empty string
Test("isMatch(nullObj, '([0-9])')", false), // null object
#endregion

#region type checking
Expand Down