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,14 @@ 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+ string . Equals (
19+ EnvironmentVariableWrapper . Instance . GetEnvironmentVariable ( DisableValidationEnvVar ) ,
20+ "true" ,
21+ StringComparison . OrdinalIgnoreCase ) ) ;
22+
1523 /// <summary>
1624 /// Validates the package ID content.
1725 /// </summary>
@@ -21,14 +29,11 @@ internal static class PackageIdValidator
2129 /// </exception>
2230 internal static void Validate ( string packageId , IEnvironmentVariableReader env = null )
2331 {
24- if ( env == null )
25- {
26- env = EnvironmentVariableWrapper . Instance ;
27- }
28-
29- string disableValidationEnvVarValue = env . GetEnvironmentVariable ( "NUGET_DISABLE_PACKAGEID_VALIDATION" ) ;
32+ bool isDisabled = env == null
33+ ? _isValidationDisabled . Value
34+ : string . Equals ( env . GetEnvironmentVariable ( DisableValidationEnvVar ) , "true" , StringComparison . OrdinalIgnoreCase ) ;
3035
31- if ( ! string . Equals ( disableValidationEnvVarValue , "true" , StringComparison . OrdinalIgnoreCase ) )
36+ if ( ! isDisabled )
3237 {
3338 if ( ! Packaging . PackageIdValidator . IsValidPackageId ( packageId ) )
3439 {
You can’t perform that action at this time.
0 commit comments