Skip to content

Commit 4b2a142

Browse files
committed
fix sonar security, move regex to source generated
1 parent fe385cf commit 4b2a142

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

libraries/tests/e2e/functions/TestUtils/OutputLogParser.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
namespace TestUtils;
44

5-
public static class OutputLogParser
5+
public static partial class OutputLogParser
66
{
77
public static List<string> ParseLogSegments(string log, out (string duration, string maxMemoryUsed, string initDuration) report)
88
{
99
var segments = new List<string>();
10-
var regex = new Regex(
11-
@"(\{(?:[^{}]|(?<open>\{)|(?<-open>\}))*\}(?(open)(?!)))|(REPORT RequestId:.*?)(?=START RequestId:|\z)",
12-
RegexOptions.Singleline);
10+
var regex = ParseLogRegex();
1311
var matches = regex.Matches(log);
1412
report = ("N/A", "N/A", "N/A");
1513

@@ -30,9 +28,7 @@ public static List<string> ParseLogSegments(string log, out (string duration, st
3028

3129
public static (string duration, string maxMemoryUsed, string initDuration) ExtractReportMetrics(string report)
3230
{
33-
var regex = new Regex(
34-
@"Duration: (?<duration>\d+\.\d+) ms.*?Max Memory Used: (?<maxMemory>\d+) MB(?:.*?Init Duration: (?<initDuration>\d+\.\d+) ms)?",
35-
RegexOptions.Singleline);
31+
var regex = ExtractMetricsRegex();
3632
var match = regex.Match(report);
3733

3834
if (!match.Success) return ("N/A", "N/A", "N/A");
@@ -43,4 +39,9 @@ public static (string duration, string maxMemoryUsed, string initDuration) Extra
4339

4440
return (duration, maxMemoryUsed, initDuration);
4541
}
42+
43+
[GeneratedRegex(@"Duration: (?<duration>\d+\.\d+) ms.*?Max Memory Used: (?<maxMemory>\d+) MB(?:.*?Init Duration: (?<initDuration>\d+\.\d+) ms)?", RegexOptions.Singleline)]
44+
private static partial Regex ExtractMetricsRegex();
45+
[GeneratedRegex(@"(\{(?:[^{}]|(?<open>\{)|(?<-open>\}))*\}(?(open)(?!)))|(REPORT RequestId:.*?)(?=START RequestId:|\z)", RegexOptions.Singleline)]
46+
private static partial Regex ParseLogRegex();
4647
}

0 commit comments

Comments
 (0)