@@ -15,7 +15,7 @@ namespace NuGetGallery
1515{
1616 public class ReservedNamespaceService : IReservedNamespaceService
1717 {
18- private static readonly Regex NamespaceRegex = new Regex ( @"^\w+([_.-]\w+)*[.]?$" , RegexOptions . Compiled | RegexOptions . ExplicitCapture ) ;
18+ private static readonly Regex NamespaceRegex = new Regex ( @"^\w+([_.-]\w+)*[.- ]?$" , RegexOptions . Compiled | RegexOptions . ExplicitCapture ) ;
1919
2020 public IEntitiesContext EntitiesContext { get ; protected set ; }
2121 public IEntityRepository < ReservedNamespace > ReservedNamespaceRepository { get ; protected set ; }
@@ -47,7 +47,14 @@ public async Task AddReservedNamespaceAsync(ReservedNamespace newNamespace)
4747 throw new ArgumentNullException ( nameof ( newNamespace ) ) ;
4848 }
4949
50- ValidateNamespace ( newNamespace . Value ) ;
50+ try
51+ {
52+ ValidateNamespace ( newNamespace . Value ) ;
53+ }
54+ catch ( ArgumentException ex )
55+ {
56+ throw new InvalidOperationException ( ex . Message , ex ) ;
57+ }
5158
5259 var matchingReservedNamespaces = FindAllReservedNamespacesForPrefix ( prefix : newNamespace . Value , getExactMatches : ! newNamespace . IsPrefix ) ;
5360 if ( matchingReservedNamespaces . Any ( ) )
@@ -348,12 +355,12 @@ public static void ValidateNamespace(string value)
348355 throw new ArgumentException ( Strings . ReservedNamespace_InvalidNamespace ) ;
349356 }
350357
351- if ( value . Length > NuGet . Services . Entities . Constants . MaxPackageIdLength )
358+ if ( value . Length > Constants . MaxPackageIdLength )
352359 {
353360 throw new ArgumentException ( string . Format (
354361 CultureInfo . CurrentCulture ,
355362 Strings . ReservedNamespace_NamespaceExceedsLength ,
356- NuGet . Services . Entities . Constants . MaxPackageIdLength ) ) ;
363+ Constants . MaxPackageIdLength ) ) ;
357364 }
358365
359366 if ( ! NamespaceRegex . IsMatch ( value ) )
0 commit comments