Skip to content
Open
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
Prev Previous commit
Next Next commit
Rename regex properties to PascalCase per feedback
Co-authored-by: stephentoub <[email protected]>
  • Loading branch information
Copilot and stephentoub committed Dec 10, 2025
commit b83d4fb1293c6dffcc1f4e94dd9e4dc765fd78e8
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,28 @@ internal partial class DbConnectionOptions

#if NET
[GeneratedRegex(ConnectionStringPattern, RegexOptions.ExplicitCapture)]
private static partial Regex s_connectionStringRegex { get; }
private static partial Regex ConnectionStringRegex { get; }

[GeneratedRegex(ConnectionStringPatternOdbc, RegexOptions.ExplicitCapture)]
private static partial Regex s_connectionStringRegexOdbc { get; }
private static partial Regex ConnectionStringRegexOdbc { get; }
#else
private static Regex s_connectionStringRegex { get; } = new Regex(ConnectionStringPattern, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
private static Regex s_connectionStringRegexOdbc { get; } = new Regex(ConnectionStringPatternOdbc, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
private static Regex ConnectionStringRegex { get; } = new Regex(ConnectionStringPattern, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
private static Regex ConnectionStringRegexOdbc { get; } = new Regex(ConnectionStringPatternOdbc, RegexOptions.ExplicitCapture | RegexOptions.Compiled);
#endif
#endif
internal const string DataDirectory = "|datadirectory|";

#if NET
[GeneratedRegex("^(?![;\\s])[^\\p{Cc}]+(?<!\\s)$")]
private static partial Regex s_connectionStringValidKeyRegex { get; } // key not allowed to start with semi-colon or space or contain non-visible characters or end with space
private static partial Regex ConnectionStringValidKeyRegex { get; } // key not allowed to start with semi-colon or space or contain non-visible characters or end with space
[GeneratedRegex("^[^\"'=;\\s\\p{Cc}]*$")]
private static partial Regex s_connectionStringQuoteValueRegex { get; } // generally do not quote the value if it matches the pattern
private static partial Regex ConnectionStringQuoteValueRegex { get; } // generally do not quote the value if it matches the pattern
[GeneratedRegex("^\\{([^\\}\u0000]|\\}\\})*\\}$", RegexOptions.ExplicitCapture)]
private static partial Regex s_connectionStringQuoteOdbcValueRegex { get; } // do not quote odbc value if it matches this pattern
private static partial Regex ConnectionStringQuoteOdbcValueRegex { get; } // do not quote odbc value if it matches this pattern
#else
private static Regex s_connectionStringValidKeyRegex { get; } = new Regex("^(?![;\\s])[^\\p{Cc}]+(?<!\\s)$", RegexOptions.Compiled); // key not allowed to start with semi-colon or space or contain non-visible characters or end with space
private static Regex s_connectionStringQuoteValueRegex { get; } = new Regex("^[^\"'=;\\s\\p{Cc}]*$", RegexOptions.Compiled); // generally do not quote the value if it matches the pattern
private static Regex s_connectionStringQuoteOdbcValueRegex { get; } = new Regex("^\\{([^\\}\u0000]|\\}\\})*\\}$", RegexOptions.ExplicitCapture | RegexOptions.Compiled); // do not quote odbc value if it matches this pattern
private static Regex ConnectionStringValidKeyRegex { get; } = new Regex("^(?![;\\s])[^\\p{Cc}]+(?<!\\s)$", RegexOptions.Compiled); // key not allowed to start with semi-colon or space or contain non-visible characters or end with space
private static Regex ConnectionStringQuoteValueRegex { get; } = new Regex("^[^\"'=;\\s\\p{Cc}]*$", RegexOptions.Compiled); // generally do not quote the value if it matches the pattern
private static Regex ConnectionStringQuoteOdbcValueRegex { get; } = new Regex("^\\{([^\\}\u0000]|\\}\\})*\\}$", RegexOptions.ExplicitCapture | RegexOptions.Compiled); // do not quote odbc value if it matches this pattern
#endif

// connection string common keywords
Expand Down Expand Up @@ -411,7 +411,7 @@ private static bool IsKeyNameValid([NotNullWhen(true)] string? keyname)
if (null != keyname)
{
#if DEBUG
bool compValue = s_connectionStringValidKeyRegex.IsMatch(keyname);
bool compValue = ConnectionStringValidKeyRegex.IsMatch(keyname);
Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))) == compValue, "IsValueValid mismatch with regex");
#endif
// string.Contains(char) is .NetCore2.1+ specific
Expand All @@ -425,7 +425,7 @@ private static bool IsKeyNameValid([NotNullWhen(true)] string? keyname)
private static Dictionary<string, string> SplitConnectionString(string connectionString, Dictionary<string, string>? synonyms, bool firstKey)
{
var parsetable = new Dictionary<string, string>();
Regex parser = (firstKey ? s_connectionStringRegexOdbc : s_connectionStringRegex);
Regex parser = (firstKey ? ConnectionStringRegexOdbc : ConnectionStringRegex);

const int KeyIndex = 1, ValueIndex = 2;
Debug.Assert(KeyIndex == parser.GroupNumberFromName("key"), "wrong key index");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
ADP.CheckArgumentNull(builder, nameof(builder));
ADP.CheckArgumentLength(keyName, nameof(keyName));

if ((null == keyName) || !s_connectionStringValidKeyRegex.IsMatch(keyName))
if ((null == keyName) || !ConnectionStringValidKeyRegex.IsMatch(keyName))
{
throw ADP.InvalidKeyname(keyName);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
if ((0 < keyValue.Length) &&
// string.Contains(char) is .NetCore2.1+ specific
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase)) &&
!s_connectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
!ConnectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
{
// always quote Driver value (required for ODBC Version 2.65 and earlier)
// always quote values that contain a ';'
Expand All @@ -100,7 +100,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
builder.Append(keyValue);
}
}
else if (s_connectionStringQuoteValueRegex.IsMatch(keyValue))
else if (ConnectionStringQuoteValueRegex.IsMatch(keyValue))
{
// <value> -> <value>
builder.Append(keyValue);
Expand Down Expand Up @@ -184,7 +184,7 @@ static partial void DebugTraceKeyValuePair(string keyname, string? keyvalue, Dic

internal static void ValidateKeyValuePair(string keyword, string value)
{
if ((null == keyword) || !s_connectionStringValidKeyRegex.IsMatch(keyword))
if ((null == keyword) || !ConnectionStringValidKeyRegex.IsMatch(keyword))
{
throw ADP.InvalidKeyname(keyword);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
ADP.CheckArgumentNull(builder, nameof(builder));
ADP.CheckArgumentLength(keyName, nameof(keyName));

if ((null == keyName) || !s_connectionStringValidKeyRegex.IsMatch(keyName))
if ((null == keyName) || !ConnectionStringValidKeyRegex.IsMatch(keyName))
{
throw ADP.InvalidKeyname(keyName);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
if ((0 < keyValue.Length) &&
// string.Contains(char) is .NetCore2.1+ specific
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || (string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase))) &&
!s_connectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
!ConnectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
{
// always quote Driver value (required for ODBC Version 2.65 and earlier)
// always quote values that contain a ';'
Expand All @@ -161,7 +161,7 @@ internal static void AppendKeyValuePairBuilder(StringBuilder builder, string key
builder.Append(keyValue);
}
}
else if (s_connectionStringQuoteValueRegex.IsMatch(keyValue))
else if (ConnectionStringQuoteValueRegex.IsMatch(keyValue))
{
// <value> -> <value>
builder.Append(keyValue);
Expand Down Expand Up @@ -446,7 +446,7 @@ internal string ExpandKeyword(string keyword, string replacementValue)

internal static void ValidateKeyValuePair(string keyword, string value)
{
if ((null == keyword) || !s_connectionStringValidKeyRegex.IsMatch(keyword))
if ((null == keyword) || !ConnectionStringValidKeyRegex.IsMatch(keyword))
{
throw ADP.InvalidKeyname(keyword);
}
Expand Down
Loading