From e11a383c0ae446eb1e99c104e6cf0f97117a14f6 Mon Sep 17 00:00:00 2001 From: Sebastien Marichal Date: Thu, 25 Jan 2024 19:11:44 +0100 Subject: [PATCH] Add UTs for S6444 (#8614) --- .../Rules/SpecifyTimeoutOnRegexTest.cs | 10 ++++++++-- .../SpecifyTimeoutOnRegex.DefaultMatchTimeout.cs | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 analyzers/tests/SonarAnalyzer.Test/TestCases/Hotspots/SpecifyTimeoutOnRegex.DefaultMatchTimeout.cs 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 +}