Skip to content

Commit

Permalink
Warm up the query string obfuscator regex (#5266)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingosse authored Mar 8, 2024
1 parent 753d00d commit de4d915
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// <copyright file="Obfuscator.cs" company="Datadog">
// <copyright file="Obfuscator.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

// turns out strict formatting and optional compilation don't like each other
#pragma warning disable SA1001, SA1116, SA1118

using System;
using System.Text.RegularExpressions;
using Datadog.Trace.Logging;
Expand All @@ -29,6 +26,17 @@ internal Obfuscator(string pattern, TimeSpan timeout, IDatadogLogger logger)
RegexOptions.IgnorePatternWhitespace;

_regex = new Regex(pattern, options, _timeout);

try
{
// Warmup the regex
// Can't use empty string, space, or dot, as they are optimized and don't actually trigger the compilation
_ = _regex.Match("o");
}
catch
{
// Nothing to log here
}
}

/// <summary>
Expand Down

0 comments on commit de4d915

Please sign in to comment.