@@ -10,112 +10,109 @@ internal static partial class RegexPatterns
1010 private const RegexOptions Options = RegexOptions . IgnoreCase | RegexOptions . Compiled ;
1111 private static readonly TimeSpan DefaultTimeout = TimeSpan . FromSeconds ( 2 ) ; // unified timeout for non-GeneratedRegex fallbacks
1212
13- internal static partial class Common
14- {
15- [ StringSyntax ( StringSyntaxAttribute . Regex ) ]
16- internal const string SwitchArgumentRegexPattern = @"/\w+:" ;
13+ [ StringSyntax ( StringSyntaxAttribute . Regex ) ]
14+ private const string SwitchArgumentRegexPattern = @"/\w+:" ;
1715
18- [ StringSyntax ( StringSyntaxAttribute . Regex ) ]
19- internal const string ObscurePasswordRegexPattern = "(https?://)(.+)(:.+@)" ;
16+ [ StringSyntax ( StringSyntaxAttribute . Regex ) ]
17+ private const string ObscurePasswordRegexPattern = "(https?://)(.+)(:.+@)" ;
2018
21- [ StringSyntax ( StringSyntaxAttribute . Regex ) ]
22- internal const string ExpandTokensRegexPattern =
23- """
24- \{ # Opening brace
25- (?: # Start of either env or member expression
26- env:(?!env:)(?<envvar>[A-Za-z_][A-Za-z0-9_]*) # Only a single env: prefix, not followed by another env:
27- | # OR
28- (?<member>[A-Za-z_][A-Za-z0-9_]*) # member/property name
29- (?: # Optional format specifier
30- :(?<format>[A-Za-z0-9\.\-,]+) # Colon followed by format string (no spaces, ?, or }), format cannot contain colon
31- )? # Format is optional
32- ) # End group for env or member
33- (?: # Optional fallback group
34- \s*\?\?\s+ # '??' operator with optional whitespace: exactly two question marks for fallback
35- (?: # Fallback value alternatives:
36- (?<fallback>\w+) # A single word fallback
37- | # OR
38- "(?<fallback>[^"]*)" # A quoted string fallback
39- )
40- )? # Fallback is optional
41- \}
42- """ ;
19+ [ StringSyntax ( StringSyntaxAttribute . Regex ) ]
20+ private const string ExpandTokensRegexPattern =
21+ """
22+ \{ # Opening brace
23+ (?: # Start of either env or member expression
24+ env:(?!env:)(?<envvar>[A-Za-z_][A-Za-z0-9_]*) # Only a single env: prefix, not followed by another env:
25+ | # OR
26+ (?<member>[A-Za-z_][A-Za-z0-9_]*) # member/property name
27+ (?: # Optional format specifier
28+ :(?<format>[A-Za-z0-9\.\-,]+) # Colon followed by format string (no spaces, ?, or }), format cannot contain colon
29+ )? # Format is optional
30+ ) # End group for env or member
31+ (?: # Optional fallback group
32+ \s*\?\?\s+ # '??' operator with optional whitespace: exactly two question marks for fallback
33+ (?: # Fallback value alternatives:
34+ (?<fallback>\w+) # A single word fallback
35+ | # OR
36+ "(?<fallback>[^"]*)" # A quoted string fallback
37+ )
38+ )? # Fallback is optional
39+ \}
40+ """ ;
4341
44- /// <summary>
45- /// Allow alphanumeric, underscore, colon (for custom format specification), hyphen, and dot
46- /// </summary>
47- [ StringSyntax ( StringSyntaxAttribute . Regex , Options ) ]
48- internal const string SanitizeEnvVarNameRegexPattern = @"^[A-Za-z0-9_:\-\.]+$" ;
42+ /// <summary>
43+ /// Allow alphanumeric, underscore, colon (for custom format specification), hyphen, and dot
44+ /// </summary>
45+ [ StringSyntax ( StringSyntaxAttribute . Regex , Options ) ]
46+ internal const string SanitizeEnvVarNameRegexPattern = @"^[A-Za-z0-9_:\-\.]+$" ;
4947
50- /// <summary>
51- /// Allow alphanumeric, underscore, and dot for property/field access
52- /// </summary>
53- [ StringSyntax ( StringSyntaxAttribute . Regex , Options ) ]
54- internal const string SanitizeMemberNameRegexPattern = @"^[A-Za-z0-9_\.]+$" ;
48+ /// <summary>
49+ /// Allow alphanumeric, underscore, and dot for property/field access
50+ /// </summary>
51+ [ StringSyntax ( StringSyntaxAttribute . Regex , Options ) ]
52+ internal const string SanitizeMemberNameRegexPattern = @"^[A-Za-z0-9_\.]+$" ;
5553
56- [ StringSyntax ( StringSyntaxAttribute . Regex , Options ) ]
57- internal const string SanitizeNameRegexPattern = "[^a-zA-Z0-9-]" ;
54+ [ StringSyntax ( StringSyntaxAttribute . Regex , Options ) ]
55+ internal const string SanitizeNameRegexPattern = "[^a-zA-Z0-9-]" ;
5856
5957#if NET9_0_OR_GREATER
60- [ GeneratedRegex ( SwitchArgumentRegexPattern , Options ) ]
61- public static partial Regex SwitchArgumentRegex { get ; }
58+ [ GeneratedRegex ( SwitchArgumentRegexPattern , Options ) ]
59+ public static partial Regex SwitchArgumentRegex { get ; }
6260#else
63- [ GeneratedRegex ( SwitchArgumentRegexPattern , Options ) ]
64- private static partial Regex SwitchArgumentRegexImpl ( ) ;
61+ [ GeneratedRegex ( SwitchArgumentRegexPattern , Options ) ]
62+ private static partial Regex SwitchArgumentRegexImpl ( ) ;
6563
66- public static Regex SwitchArgumentRegex { get ; } = SwitchArgumentRegexImpl ( ) ;
64+ public static Regex SwitchArgumentRegex { get ; } = SwitchArgumentRegexImpl ( ) ;
6765#endif
6866
6967#if NET9_0_OR_GREATER
70- [ GeneratedRegex ( ObscurePasswordRegexPattern , Options ) ]
71- public static partial Regex ObscurePasswordRegex { get ; }
68+ [ GeneratedRegex ( ObscurePasswordRegexPattern , Options ) ]
69+ public static partial Regex ObscurePasswordRegex { get ; }
7270#else
73- [ GeneratedRegex ( ObscurePasswordRegexPattern , Options ) ]
74- private static partial Regex ObscurePasswordRegexImpl ( ) ;
71+ [ GeneratedRegex ( ObscurePasswordRegexPattern , Options ) ]
72+ private static partial Regex ObscurePasswordRegexImpl ( ) ;
7573
76- public static Regex ObscurePasswordRegex { get ; } = ObscurePasswordRegexImpl ( ) ;
74+ public static Regex ObscurePasswordRegex { get ; } = ObscurePasswordRegexImpl ( ) ;
7775#endif
7876
7977#if NET9_0_OR_GREATER
80- [ GeneratedRegex ( ExpandTokensRegexPattern , RegexOptions . IgnorePatternWhitespace | Options ) ]
81- public static partial Regex ExpandTokensRegex { get ; }
78+ [ GeneratedRegex ( ExpandTokensRegexPattern , RegexOptions . IgnorePatternWhitespace | Options ) ]
79+ public static partial Regex ExpandTokensRegex { get ; }
8280#else
83- [ GeneratedRegex ( ExpandTokensRegexPattern , RegexOptions . IgnorePatternWhitespace | Options ) ]
84- private static partial Regex ExpandTokensRegexImpl ( ) ;
81+ [ GeneratedRegex ( ExpandTokensRegexPattern , RegexOptions . IgnorePatternWhitespace | Options ) ]
82+ private static partial Regex ExpandTokensRegexImpl ( ) ;
8583
86- public static Regex ExpandTokensRegex { get ; } = ExpandTokensRegexImpl ( ) ;
84+ public static Regex ExpandTokensRegex { get ; } = ExpandTokensRegexImpl ( ) ;
8785#endif
8886
8987#if NET9_0_OR_GREATER
90- [ GeneratedRegex ( SanitizeEnvVarNameRegexPattern , Options ) ]
91- public static partial Regex SanitizeEnvVarNameRegex { get ; }
88+ [ GeneratedRegex ( SanitizeEnvVarNameRegexPattern , Options ) ]
89+ public static partial Regex SanitizeEnvVarNameRegex { get ; }
9290#else
93- [ GeneratedRegex ( SanitizeEnvVarNameRegexPattern , Options ) ]
94- private static partial Regex SanitizeEnvVarNameRegexImpl ( ) ;
91+ [ GeneratedRegex ( SanitizeEnvVarNameRegexPattern , Options ) ]
92+ private static partial Regex SanitizeEnvVarNameRegexImpl ( ) ;
9593
96- public static Regex SanitizeEnvVarNameRegex { get ; } = SanitizeEnvVarNameRegexImpl ( ) ;
94+ public static Regex SanitizeEnvVarNameRegex { get ; } = SanitizeEnvVarNameRegexImpl ( ) ;
9795#endif
9896
9997#if NET9_0_OR_GREATER
100- [ GeneratedRegex ( SanitizeMemberNameRegexPattern , Options ) ]
101- public static partial Regex SanitizeMemberNameRegex { get ; }
98+ [ GeneratedRegex ( SanitizeMemberNameRegexPattern , Options ) ]
99+ public static partial Regex SanitizeMemberNameRegex { get ; }
102100#else
103- [ GeneratedRegex ( SanitizeMemberNameRegexPattern , Options ) ]
104- private static partial Regex SanitizeMemberNameRegexImpl ( ) ;
101+ [ GeneratedRegex ( SanitizeMemberNameRegexPattern , Options ) ]
102+ private static partial Regex SanitizeMemberNameRegexImpl ( ) ;
105103
106- public static Regex SanitizeMemberNameRegex { get ; } = SanitizeMemberNameRegexImpl ( ) ;
104+ public static Regex SanitizeMemberNameRegex { get ; } = SanitizeMemberNameRegexImpl ( ) ;
107105#endif
108106
109107#if NET9_0_OR_GREATER
110- [ GeneratedRegex ( SanitizeNameRegexPattern , Options ) ]
111- public static partial Regex SanitizeNameRegex { get ; }
108+ [ GeneratedRegex ( SanitizeNameRegexPattern , Options ) ]
109+ public static partial Regex SanitizeNameRegex { get ; }
112110#else
113- [ GeneratedRegex ( SanitizeNameRegexPattern , Options ) ]
114- private static partial Regex SanitizeNameRegexImpl ( ) ;
111+ [ GeneratedRegex ( SanitizeNameRegexPattern , Options ) ]
112+ private static partial Regex SanitizeNameRegexImpl ( ) ;
115113
116- public static Regex SanitizeNameRegex { get ; } = SanitizeNameRegexImpl ( ) ;
114+ public static Regex SanitizeNameRegex { get ; } = SanitizeNameRegexImpl ( ) ;
117115#endif
118- }
119116
120117 public static class Cache
121118 {
@@ -137,12 +134,12 @@ public static Regex GetOrAdd([StringSyntax(StringSyntaxAttribute.Regex)] string
137134 // Central descriptor list – single source of truth for known patterns. Order not significant.
138135 private static readonly RegexDescriptor [ ] Descriptors =
139136 [
140- new ( Common . SwitchArgumentRegexPattern , Common . SwitchArgumentRegex ) ,
141- new ( Common . ObscurePasswordRegexPattern , Common . ObscurePasswordRegex ) ,
142- new ( Common . ExpandTokensRegexPattern , Common . ExpandTokensRegex ) ,
143- new ( Common . SanitizeEnvVarNameRegexPattern , Common . SanitizeEnvVarNameRegex ) ,
144- new ( Common . SanitizeMemberNameRegexPattern , Common . SanitizeMemberNameRegex ) ,
145- new ( Common . SanitizeNameRegexPattern , Common . SanitizeNameRegex ) ,
137+ new ( SwitchArgumentRegexPattern , SwitchArgumentRegex ) ,
138+ new ( ObscurePasswordRegexPattern , ObscurePasswordRegex ) ,
139+ new ( ExpandTokensRegexPattern , ExpandTokensRegex ) ,
140+ new ( SanitizeEnvVarNameRegexPattern , SanitizeEnvVarNameRegex ) ,
141+ new ( SanitizeMemberNameRegexPattern , SanitizeMemberNameRegex ) ,
142+ new ( SanitizeNameRegexPattern , SanitizeNameRegex ) ,
146143 new ( Configuration . DefaultTagPrefixRegexPattern , Configuration . DefaultTagPrefixRegex ) ,
147144 new ( Configuration . DefaultVersionInBranchRegexPattern , Configuration . DefaultVersionInBranchRegex ) ,
148145 new ( Configuration . MainBranchRegexPattern , Configuration . MainBranchRegex ) ,
0 commit comments