Skip to content

Commit b56fc3c

Browse files
Fix hotspots on dotnet solution (#103)
1 parent ac7575e commit b56fc3c

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

sonar-text-dotnet/src/SonarLint.Secrets.DotNet/DummySecretDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace SonarLint.Secrets.DotNet
3030
internal sealed class DummySecretDetector : ISecretDetector
3131
{
3232
private const string PasswordPattern = "sonarlint\\.internal\\.dummy\\.password\\=(?<pwd>[\\w-]+)\\s";
33-
private static readonly Regex StackRegExp = new Regex(PasswordPattern);
33+
private static readonly Regex StackRegExp = new Regex(PasswordPattern, RegexOptions.None, RegexConstants.DefaultTimeout);
3434

3535
private const string RuleKey = "secrets:sonarlint.internal.dummy.pwd";
3636

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* SonarAnalyzer for Text
3+
* Copyright (C) 2021-2023 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
21+
using System;
22+
23+
namespace SonarLint.Secrets.DotNet
24+
{
25+
public static class RegexConstants
26+
{
27+
public static TimeSpan DefaultTimeout => TimeSpan.FromMilliseconds(100);
28+
}
29+
}

sonar-text-dotnet/src/SonarLint.Secrets.DotNet/Rules/Matching/RegexMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class RegexMatcher : ISecretsMatcher
3030

3131
public RegexMatcher(string stringPattern)
3232
{
33-
this.pattern = new Regex(stringPattern, RegexOptions.Compiled);
33+
this.pattern = new Regex(stringPattern, RegexOptions.Compiled, RegexConstants.DefaultTimeout);
3434
}
3535

3636
public List<Match> FindIn(string input)

0 commit comments

Comments
 (0)