diff --git a/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyTimeoutOnRegexTest.cs b/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyTimeoutOnRegexTest.cs index 846b8350df8..ff08af5910e 100644 --- a/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyTimeoutOnRegexTest.cs +++ b/analyzers/tests/SonarAnalyzer.Test/Rules/SpecifyTimeoutOnRegexTest.cs @@ -45,8 +45,14 @@ public void SpecifyTimeoutOnRegex_CS() => [TestMethod] public void SpecifyTimeoutOnRegex_CSharp8() => builderCS.AddPaths("SpecifyTimeoutOnRegex.CSharp9.cs") - .WithOptions(ParseOptionsHelper.FromCSharp9) - .Verify(); + .WithOptions(ParseOptionsHelper.FromCSharp9) + .Verify(); + + [TestMethod] + public void SpecifyTimeoutOnRegex_DefaultMatchTimeout() => + builderCS.AddPaths("SpecifyTimeoutOnRegex.DefaultMatchTimeout.cs") + .WithTopLevelStatements() + .Verify(); [TestMethod] public void SpecifyTimeoutOnRegex_VB() => diff --git a/analyzers/tests/SonarAnalyzer.Test/TestCases/Hotspots/SpecifyTimeoutOnRegex.DefaultMatchTimeout.cs b/analyzers/tests/SonarAnalyzer.Test/TestCases/Hotspots/SpecifyTimeoutOnRegex.DefaultMatchTimeout.cs new file mode 100644 index 00000000000..2da44dad331 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.Test/TestCases/Hotspots/SpecifyTimeoutOnRegex.DefaultMatchTimeout.cs @@ -0,0 +1,10 @@ +using System.Text.RegularExpressions; +using System; + +AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromMilliseconds(100)); + +void RegexPattern(string input) +{ + _ = new Regex(".+@.+", RegexOptions.None); // Noncompliant, FP REGEX_DEFAULT_MATCH_TIMEOUT is set in the AppDomain + _ = Regex.IsMatch(input, "[0-9]+"); // Noncompliant, FP REGEX_DEFAULT_MATCH_TIMEOUT is set in the AppDomain +}