File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
src/NuGet.Core/NuGet.Packaging/PackageCreation/Utility
test/NuGet.Core.Tests/NuGet.Packaging.Test Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,9 @@ namespace NuGet.Packaging
11
11
public static class PackageIdValidator
12
12
{
13
13
public const int MaxPackageIdLength = 100 ;
14
- private static readonly Regex IdRegex = new Regex ( @"^\w+([_.-]\w+)*$" , RegexOptions . IgnoreCase | RegexOptions . ExplicitCapture | RegexOptions . CultureInvariant ) ;
14
+ private static readonly Regex IdRegex = new Regex ( pattern : @"^\w+([.-]\w+)*$" ,
15
+ options : RegexOptions . IgnoreCase | RegexOptions . ExplicitCapture | RegexOptions . CultureInvariant ,
16
+ matchTimeout : TimeSpan . FromSeconds ( 10 ) ) ;
15
17
16
18
public static bool IsValidPackageId ( string packageId )
17
19
{
Original file line number Diff line number Diff line change @@ -159,6 +159,32 @@ public void DotToolsIsNotAllowed()
159
159
Assert . False ( isValid ) ;
160
160
}
161
161
162
+ [ Fact ]
163
+ public void IsValidPackageId_PackageIdWithTwoUnderscores_Success ( )
164
+ {
165
+ // Arrange
166
+ string packageId = "Hello__World" ;
167
+
168
+ // Act
169
+ bool isValid = PackageIdValidator . IsValidPackageId ( packageId ) ;
170
+
171
+ // Assert
172
+ Assert . True ( isValid ) ;
173
+ }
174
+
175
+ [ Fact ]
176
+ public void IsValidPackageId_LongPackageIdWithUnMatchedCharAtTheEnd_Fails ( )
177
+ {
178
+ // Arrange
179
+ string packageId = string . Concat ( new string ( '_' , 100 ) , "!" ) ;
180
+
181
+ // Act
182
+ bool isValid = PackageIdValidator . IsValidPackageId ( packageId ) ;
183
+
184
+ // Assert
185
+ Assert . False ( isValid ) ;
186
+ }
187
+
162
188
[ Theory ]
163
189
[ InlineData ( 101 ) ]
164
190
[ InlineData ( 102 ) ]
You can’t perform that action at this time.
0 commit comments