Skip to content

Commit

Permalink
Merge pull request #867 from Project-MONAI/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
neildsouth authored Aug 24, 2023
2 parents 6fd4ef2 + 1279109 commit fb02642
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ConditionalParameterParser : IConditionalParameterParser
private readonly IPayloadService _payloadService;
private readonly IWorkflowService _workflowService;

private readonly Regex _squigglyBracketsRegex = new Regex(@"\{{(.*?)\}}");
private readonly Regex _squigglyBracketsRegex = new(@"\{{(.*?)\}}", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

private WorkflowInstance? _workflowInstance = null;
private string? _workflowInstanceId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public class ConditionalGroup

public int GroupedLogical { get; set; } = 1;

public Regex FindAnds { get; } = new Regex(@"([\s]and[\s]|[\s]AND[\s]|[\s]And[\s])");
public Regex FindAnds { get; } = new(@"([\s]and[\s]|[\s]AND[\s]|[\s]And[\s])", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

public Regex FindOrs { get; } = new Regex(@"([\s]or[\s]|[\s]OR[\s]|[\s]Or[\s])");
public Regex FindOrs { get; } = new(@"([\s]or[\s]|[\s]OR[\s]|[\s]Or[\s])", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

public Regex FindBrackets { get; } = new Regex(@"((?<!\[)\()");
public Regex FindBrackets { get; } = new(@"((?<!\[)\()", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

public Regex FindCloseBrackets { get; } = new Regex(@"((?<!\[)\))");
public Regex FindCloseBrackets { get; } = new(@"((?<!\[)\))", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));

private string[] ParseOrs(string input) => FindOrs.SplitOnce(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private async Task ValidateWorkflowSpec(Workflow workflow)
}

var taskIds = workflow.Tasks.Select(t => t.Id);
var pattern = new Regex(@"^[a-zA-Z0-9-_]+$");
var pattern = new Regex(@"^[a-zA-Z0-9-_]+$", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));
foreach (var taskId in taskIds)
{
if (pattern.IsMatch(taskId) is false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RegexExtensionsTests
[InlineData(new string[] { "test ", "( test( test" }, "test ( test( test")]
public void Regex_WhenSplitOnce_ShouldOnlyHaveArrayOfTwo(string[] expected, string stringToSplit)
{
var regexFindBrackets = new Regex(@"((?<!\[)\()");
var regexFindBrackets = new Regex(@"((?<!\[)\()", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));
var result = regexFindBrackets.SplitOnce(stringToSplit);
Assert.Equal(expected, result);
Assert.Equal(2, result.Length);
Expand All @@ -40,7 +40,7 @@ public void Regex_WhenSplitOnce_ShouldOnlyHaveArrayOfTwo(string[] expected, stri
public void Regex_WhenSplitOnceProvidedNullInput_ShouldThrowException()
{
var expectedErrorMessage = "Value cannot be null. (Parameter 'input')";
var regexFindBrackets = new Regex(@"((?<!\[)\()");
var regexFindBrackets = new Regex(@"((?<!\[)\()", RegexOptions.None, matchTimeout: TimeSpan.FromSeconds(2));
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
var exception = Assert.Throws<ArgumentNullException>(() => regexFindBrackets.SplitOnce(null));
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
Expand Down

0 comments on commit fb02642

Please sign in to comment.