@@ -5,14 +5,14 @@ namespace Microsoft.NET.Build.Containers;
5
5
6
6
public static class ContainerHelpers
7
7
{
8
- private static Regex imageTagRegex = new Regex ( "^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$" ) ;
8
+ private static Regex imageTagRegex = new Regex ( @ "^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$") ;
9
9
10
- private static Regex imageNameRegex = new Regex ( "^[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*$" ) ;
10
+ private static Regex imageNameRegex = new Regex ( @ "^[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*$") ;
11
11
12
12
/// <summary>
13
13
/// Matches if the string is not lowercase or numeric, or ., _, or -.
14
14
/// </summary>
15
- private static Regex imageNameCharacters = new Regex ( "[^a-zA-Z0- 9._- ]" ) ;
15
+ private static Regex imageNameCharacters = new Regex ( @ "[^a-z0- 9._\-/ ]") ;
16
16
17
17
/// <summary>
18
18
/// Given some "fully qualified" image name (e.g. mcr.microsoft.com/dotnet/runtime), return
@@ -133,13 +133,11 @@ public static bool NormalizeImageName(string containerImageName, [NotNullWhen(fa
133
133
}
134
134
else
135
135
{
136
- if ( Char . IsUpper ( containerImageName , 0 ) )
137
- {
138
- containerImageName = Char . ToLowerInvariant ( containerImageName [ 0 ] ) + containerImageName [ 1 ..] ;
139
- } else if ( ! Char . IsLetterOrDigit ( containerImageName , 0 ) ) {
136
+ if ( ! Char . IsLetterOrDigit ( containerImageName , 0 ) ) {
140
137
throw new ArgumentException ( "The first character of the image name must be a lowercase letter or a digit." ) ;
141
138
}
142
- normalizedImageName = imageNameCharacters . Replace ( containerImageName , "-" ) ;
139
+ var loweredImageName = containerImageName . ToLowerInvariant ( ) ;
140
+ normalizedImageName = imageNameCharacters . Replace ( loweredImageName , "-" ) ;
143
141
return false ;
144
142
}
145
143
}
0 commit comments