Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup>
<NoWarn>CA1510,CA1859,CA1861,CS0618,CS1591,xUnit1044,xUnit1045</NoWarn>
<!-- S6444: Regex match timeouts use wall-clock time and fail under CPU load (#1629). -->
<NoWarn>CA1510,CA1859,CA1861,CS0618,CS1591,S6444,xUnit1044,xUnit1045</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.K3s/K3sContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public async Task<string> GetKubeconfigAsync()

var server = new UriBuilder(Uri.UriSchemeHttps, Hostname, GetMappedPublicPort(K3sBuilder.KubeSecurePort)).ToString();

return Regex.Replace(kubeconfig, "server:\\s?[:/\\.\\d\\w]+", "server: " + server, RegexOptions.None, TimeSpan.FromSeconds(1));
return Regex.Replace(kubeconfig, "server:\\s?[:/\\.\\d\\w]+", "server: " + server);
}
}
2 changes: 1 addition & 1 deletion src/Testcontainers.Neo4j/Neo4jBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Neo4jBuilder WithEnterpriseEdition(bool acceptLicenseAgreement)
else if (image.MatchVersion(v => Array.Exists(operatingSystems, v.Contains)))
{
MatchEvaluator evaluator = match => $"{enterpriseSuffix}-{match.Value}";
tag = Regex.Replace(image.Tag, string.Join("|", operatingSystems), evaluator, RegexOptions.None, TimeSpan.FromSeconds(1));
tag = Regex.Replace(image.Tag, string.Join("|", operatingSystems), evaluator);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public sealed class BuildKitImageFromDockerfileBuilder : AbstractBuilder<BuildKi
/// The id is part of the path of the file that carries the build secret inside the
/// Docker CLI container, and part of the Docker CLI argument that references it.
/// </remarks>
private static readonly Regex IdRegex = new Regex("^[A-Za-z0-9][A-Za-z0-9_.-]*$", RegexOptions.None, TimeSpan.FromSeconds(1));
private static readonly Regex IdRegex = new Regex("^[A-Za-z0-9][A-Za-z0-9_.-]*$");

/// <summary>
/// Initializes a new instance of the <see cref="BuildKitImageFromDockerfileBuilder" /> class.
Expand Down Expand Up @@ -120,7 +120,7 @@ public BuildKitImageFromDockerfileBuilder WithContextDirectory(string contextDir
/// <inheritdoc />
public BuildKitImageFromDockerfileBuilder WithDockerfile(string dockerfile)
{
var dockerfileFilePath = Regex.Replace(dockerfile, "^\\.(\\/|\\\\)", string.Empty, RegexOptions.None, TimeSpan.FromSeconds(1));
var dockerfileFilePath = Regex.Replace(dockerfile, "^\\.(\\/|\\\\)", string.Empty);
return Merge(DockerResourceConfiguration, new BuildKitImageFromDockerfileConfiguration(dockerfile: dockerfileFilePath));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers/Builders/ComposeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public sealed class ComposeBuilder : ContainerBuilder<ComposeBuilder, ComposeCon
/// </remarks>
private static readonly string[] PathSeparators = { ":", ";", "|", "," };

private static readonly Regex ProjectNameRegex = new Regex("^[a-z0-9][a-z0-9_-]*$", RegexOptions.None, TimeSpan.FromSeconds(1));
private static readonly Regex ProjectNameRegex = new Regex("^[a-z0-9][a-z0-9_-]*$");

/// <summary>
/// Initializes a new instance of the <see cref="ComposeBuilder" /> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ImageFromDockerfileBuilder WithContextDirectory(string contextDirectory)
/// <inheritdoc />
public ImageFromDockerfileBuilder WithDockerfile(string dockerfile)
{
var dockerfileFilePath = Regex.Replace(dockerfile, "^\\.(\\/|\\\\)", string.Empty, RegexOptions.None, TimeSpan.FromSeconds(1));
var dockerfileFilePath = Regex.Replace(dockerfile, "^\\.(\\/|\\\\)", string.Empty);
return Merge(DockerResourceConfiguration, new ImageFromDockerfileConfiguration(dockerfile: dockerfileFilePath));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace DotNet.Testcontainers.Configurations
{
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
Expand All @@ -10,7 +9,7 @@ internal class UntilMessageIsLogged : IWaitUntil
private readonly Regex _pattern;

public UntilMessageIsLogged(string pattern)
: this(new Regex(pattern, RegexOptions.None, TimeSpan.FromSeconds(5)))
: this(new Regex(pattern))
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers/Images/DockerImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public bool MatchVersion(Predicate<Version> predicate)
return false;
}

var versionMatch = Regex.Match(Tag, "^(\\d+)(\\.\\d+)?(\\.\\d+)?", RegexOptions.None, TimeSpan.FromSeconds(1));
var versionMatch = Regex.Match(Tag, "^(\\d+)(\\.\\d+)?(\\.\\d+)?");

if (!versionMatch.Success)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Testcontainers/Images/DockerfileArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace DotNet.Testcontainers.Images
/// </summary>
internal sealed class DockerfileArchive : ITarArchive
{
private static readonly Regex ArgLinePattern = new Regex("^ARG\\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)=(?:\"(?<value>[^\"]*)\"|'(?<value>[^']*)'|(?<value>\\S+))", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1));
private static readonly Regex ArgLinePattern = new Regex("^ARG\\s+(?<name>[A-Za-z_][A-Za-z0-9_]*)=(?:\"(?<value>[^\"]*)\"|'(?<value>[^']*)'|(?<value>\\S+))", RegexOptions.IgnoreCase);

private static readonly Regex FromLinePattern = new Regex("^FROM\\s+(?<arg>--\\S+\\s)*(?<image>\\S+).*", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1));
private static readonly Regex FromLinePattern = new Regex("^FROM\\s+(?<arg>--\\S+\\s)*(?<image>\\S+).*", RegexOptions.IgnoreCase);

private static readonly Regex VariablePattern = new Regex("\\$(\\{(?<name>[A-Za-z_][A-Za-z0-9_]*)\\}|(?<name>[A-Za-z_][A-Za-z0-9_]*))", RegexOptions.None, TimeSpan.FromSeconds(1));
private static readonly Regex VariablePattern = new Regex("\\$(\\{(?<name>[A-Za-z_][A-Za-z0-9_]*)\\}|(?<name>[A-Za-z_][A-Za-z0-9_]*))");

private readonly DirectoryInfo _contextDirectory;

Expand Down Expand Up @@ -222,7 +222,7 @@ public async Task<string> Tar(CancellationToken ct = default)

var dockerIgnoreFile = new DockerIgnoreFile(_dockerfileDirectory, dockerIgnoreFileName, _dockerfile.Name, _logger);

var dockerfileArchiveFileName = Regex.Replace(_image.FullName, "[^a-zA-Z0-9]", "-", RegexOptions.None, TimeSpan.FromSeconds(1)).ToLowerInvariant();
var dockerfileArchiveFileName = Regex.Replace(_image.FullName, "[^a-zA-Z0-9]", "-").ToLowerInvariant();

// Image builds that run at the same time must not share the tar archive,
// even if they build the same image.
Expand Down
4 changes: 2 additions & 2 deletions src/Testcontainers/Images/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public IgnoreFile(IEnumerable<string> patterns, ILogger logger)
{
var key = ignorePattern.Key;
var value = ignorePattern.Value;
return new KeyValuePair<Regex, bool>(new Regex(key, RegexOptions.None, TimeSpan.FromSeconds(1)), value);
return new KeyValuePair<Regex, bool>(new Regex(key), value);
})
.ToArray();

Expand Down Expand Up @@ -148,7 +148,7 @@ public bool Denies(string file)
/// </summary>
private readonly struct EscapeRegex : ISearchAndReplace<string>
{
private static readonly Regex Pattern = new Regex("[\\-\\[\\]\\/\\{\\}\\(\\)\\+\\?\\.\\\\\\^\\$\\|]", RegexOptions.None, TimeSpan.FromSeconds(1));
private static readonly Regex Pattern = new Regex("[\\-\\[\\]\\/\\{\\}\\(\\)\\+\\?\\.\\\\\\^\\$\\|]");

/// <inheritdoc />
public string Replace(string input)
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers/Images/MatchImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static ReferenceRegex()
}

private ReferenceRegex()
: base(Pattern, RegexOptions.Compiled, TimeSpan.FromSeconds(5))
: base(Pattern, RegexOptions.Compiled)
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Testcontainers.Commons/DockerfileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace DotNet.Testcontainers.Commons;

internal sealed class DockerfileParser
{
private static readonly Regex FromLinePattern = new Regex("^FROM\\s+(?<arg>--\\S+\\s)*(?<image>\\S+).*", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1));
private static readonly Regex FromLinePattern = new Regex("^FROM\\s+(?<arg>--\\S+\\s)*(?<image>\\S+).*", RegexOptions.IgnoreCase);

private readonly string _filePath;

Expand Down
6 changes: 3 additions & 3 deletions tools/Testcontainers.DocGen/BuilderDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ private string GetSummary(MemberInfo member, string fallback)
// summary of a private member from the builder source instead. The
// declaration must follow the documentation, not a line within it.
var declarationPattern = member is Type ? "class " + Regex.Escape(member.Name) + @"\b" : Regex.Escape(member.Name) + @"\(";
var match = Regex.Match(_builderSource, @"(?<doc>(?:^[ \t]*///.*\n)+)(?![ \t]*///)[^\n]*\b" + declarationPattern, RegexOptions.Multiline, TimeSpan.FromSeconds(1));
var match = Regex.Match(_builderSource, @"(?<doc>(?:^[ \t]*///.*\n)+)(?![ \t]*///)[^\n]*\b" + declarationPattern, RegexOptions.Multiline);

XElement summary = null;

if (match.Success)
{
var doc = Regex.Replace(match.Groups["doc"].Value, @"^[ \t]*/// ?", string.Empty, RegexOptions.Multiline, TimeSpan.FromSeconds(1));
var doc = Regex.Replace(match.Groups["doc"].Value, @"^[ \t]*/// ?", string.Empty, RegexOptions.Multiline);
summary = XElement.Parse("<doc>" + doc + "</doc>").Element("summary");
}

Expand All @@ -322,7 +322,7 @@ private string GetSummary(MemberInfo member, string fallback)
reference.ReplaceWith(new XElement("c", (string)reference.Attribute("cref") ?? (string)reference.Attribute("name")));
}

return Regex.Replace(string.Concat(summary.Nodes()), @"\s+", " ", RegexOptions.None, TimeSpan.FromSeconds(1)).Trim();
return Regex.Replace(string.Concat(summary.Nodes()), @"\s+", " ").Trim();
}

private string GetPortConstantCref(Setting setting)
Expand Down
6 changes: 3 additions & 3 deletions tools/Testcontainers.DocGen/MarkdownDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ internal static class MarkdownDocumentation
{
// Python-Markdown supports backslash escapes for these characters, but
// not for '<'. The tool replaces it with an entity instead.
private static readonly Regex SpecialCharacterPattern = new Regex(@"[\\`*_\[\]]", RegexOptions.None, TimeSpan.FromSeconds(1));
private static readonly Regex SpecialCharacterPattern = new Regex(@"[\\`*_\[\]]");

private static readonly Regex BacktickPattern = new Regex("`+", RegexOptions.None, TimeSpan.FromSeconds(1));
private static readonly Regex BacktickPattern = new Regex("`+");

private static readonly Dictionary<string, string> TypeAliases = new Dictionary<string, string>
{
Expand Down Expand Up @@ -68,7 +68,7 @@ private static string GetName(string cref)
{
// Render the reference without the namespace and with C# type
// aliases like the IDE, such as 'PostgreSqlBuilder.WithDatabase(string)'.
var match = Regex.Match(cref, @"^[A-Z]:(?<name>[^(]+)(?:\((?<parameters>[^)]*)\))?$", RegexOptions.None, TimeSpan.FromSeconds(1));
var match = Regex.Match(cref, @"^[A-Z]:(?<name>[^(]+)(?:\((?<parameters>[^)]*)\))?$");

var name = string.Join(".", match.Groups["name"].Value.Split('.').TakeLast(2));

Expand Down
2 changes: 1 addition & 1 deletion tools/Testcontainers.DocGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class Program

private const string GeneratedMarkdownFileSuffix = ".Generated.md";

private static readonly Regex IncludePattern = new Regex("<include file=\"(?<file>[^\"]+" + Regex.Escape(GeneratedXmlFileSuffix) + ")\" path=\"(?<path>[^\"]+)\"", RegexOptions.None, TimeSpan.FromSeconds(1));
private static readonly Regex IncludePattern = new Regex("<include file=\"(?<file>[^\"]+" + Regex.Escape(GeneratedXmlFileSuffix) + ")\" path=\"(?<path>[^\"]+)\"");

public static int Main()
{
Expand Down
Loading