Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove regex timeout for IsLocalMethod and IsTypeFilterMatch #1689

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,4 @@ coverage.*.cobertura.xml
coverage.*.opencover.xml

FolderProfile.pubxml
/NuGet.config
6 changes: 3 additions & 3 deletions src/coverlet.core/Helpers/InstrumentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class InstrumentationHelper : IInstrumentationHelper
private readonly ISourceRootTranslator _sourceRootTranslator;
private ILogger _logger;
private static readonly RegexOptions s_regexOptions =
RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase;
RegexOptions.Multiline | RegexOptions.Compiled;

public InstrumentationHelper(IProcessExitHandler processExitHandler, IRetryHelper retryHelper, IFileSystem fileSystem, ILogger logger, ISourceRootTranslator sourceRootTranslator)
{
Expand Down Expand Up @@ -420,7 +420,7 @@ public bool IsTypeIncluded(string module, string type, string[] includeFilters)
}

public bool IsLocalMethod(string method)
=> new Regex(WildcardToRegex("<*>*__*|*"), s_regexOptions, TimeSpan.FromSeconds(10)).IsMatch(method);
=> new Regex(WildcardToRegex("<*>*__*|*")).IsMatch(method);
Bertk marked this conversation as resolved.
Show resolved Hide resolved

public void SetLogger(ILogger logger)
{
Expand All @@ -442,7 +442,7 @@ private static bool IsTypeFilterMatch(string module, string type, string[] filte
typePattern = WildcardToRegex(typePattern);
modulePattern = WildcardToRegex(modulePattern);

if (new Regex(typePattern, s_regexOptions, TimeSpan.FromSeconds(10)).IsMatch(type) && new Regex(modulePattern, s_regexOptions, TimeSpan.FromSeconds(10)).IsMatch(module))
if (new Regex(typePattern).IsMatch(type) && new Regex(modulePattern).IsMatch(module))
Bertk marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);NU1301</NoWarn>
<NoWarn>$(NoWarn);NU1301;IDE0007</NoWarn>
</PropertyGroup>
</Project>
38 changes: 22 additions & 16 deletions test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,29 @@ public void TestBackupOriginalModule()
Assert.True(File.Exists(backupPath));
}

[Fact]
public void TestIsValidFilterExpression()
[Theory]
[InlineData("[*]*")]
[InlineData("[*]*core")]
[InlineData("[assembly]*")]
[InlineData("[*]type")]
[InlineData("[assembly]type")]
[InlineData("[coverlet.*.tests?]*")]
[InlineData("[*]Coverlet.Core*")]
[InlineData("[coverlet.*]*")]
public void TestIsValidFilterExpression(string pattern)
{
Assert.True(_instrumentationHelper.IsValidFilterExpression(pattern));
}

[Theory]
[InlineData("[*]")]
[InlineData("[-]*")]
[InlineData("*")]
[InlineData("][")]
[InlineData(null)]
public void TestInValidFilterExpression(string pattern)
{
Assert.True(_instrumentationHelper.IsValidFilterExpression("[*]*"));
Assert.True(_instrumentationHelper.IsValidFilterExpression("[*]*core"));
Assert.True(_instrumentationHelper.IsValidFilterExpression("[assembly]*"));
Assert.True(_instrumentationHelper.IsValidFilterExpression("[*]type"));
Assert.True(_instrumentationHelper.IsValidFilterExpression("[assembly]type"));
Assert.False(_instrumentationHelper.IsValidFilterExpression("[*]"));
Assert.False(_instrumentationHelper.IsValidFilterExpression("[-]*"));
Assert.False(_instrumentationHelper.IsValidFilterExpression("*"));
Assert.False(_instrumentationHelper.IsValidFilterExpression("]["));
Assert.False(_instrumentationHelper.IsValidFilterExpression("["));
Assert.False(_instrumentationHelper.IsValidFilterExpression("[assembly][*"));
Assert.False(_instrumentationHelper.IsValidFilterExpression("[assembly]*]"));
Assert.False(_instrumentationHelper.IsValidFilterExpression("[]"));
Assert.False(_instrumentationHelper.IsValidFilterExpression(null));
Assert.False(_instrumentationHelper.IsValidFilterExpression(pattern));
}

[Fact]
Expand Down