File tree Expand file tree Collapse file tree
src/NuGet.Core/NuGet.Protocol/Utility Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ namespace NuGet.Protocol
1212{
1313 internal static class PackageIdValidator
1414 {
15+ private const string DisableValidationEnvVar = "NUGET_DISABLE_PACKAGEID_VALIDATION" ;
16+
17+ private static readonly Lazy < bool > IsValidationDisabled = new Lazy < bool > ( ( ) =>
18+ IsPackageIdValidationDisabled ( EnvironmentVariableWrapper . Instance ) ) ;
19+
1520 /// <summary>
1621 /// Validates the package ID content.
1722 /// </summary>
@@ -21,20 +26,20 @@ internal static class PackageIdValidator
2126 /// </exception>
2227 internal static void Validate ( string packageId , IEnvironmentVariableReader env = null )
2328 {
24- if ( env == null )
25- {
26- env = EnvironmentVariableWrapper . Instance ;
27- }
28-
29- string disableValidationEnvVarValue = env . GetEnvironmentVariable ( "NUGET_DISABLE_PACKAGEID_VALIDATION" ) ;
29+ bool isDisabled = env == null
30+ ? IsValidationDisabled . Value
31+ : IsPackageIdValidationDisabled ( env ) ;
3032
31- if ( ! string . Equals ( disableValidationEnvVarValue , "true" , StringComparison . OrdinalIgnoreCase ) )
33+ if ( ! isDisabled )
3234 {
3335 if ( ! Packaging . PackageIdValidator . IsValidPackageId ( packageId ) )
3436 {
3537 throw new InvalidPackageIdException ( string . Format ( CultureInfo . CurrentCulture , Strings . Error_Invalid_package_id , packageId ) ) ;
3638 }
3739 }
3840 }
41+
42+ private static bool IsPackageIdValidationDisabled ( IEnvironmentVariableReader env ) =>
43+ string . Equals ( env . GetEnvironmentVariable ( DisableValidationEnvVar ) , bool . TrueString , StringComparison . OrdinalIgnoreCase ) ;
3944 }
4045}
You can’t perform that action at this time.
0 commit comments