Skip to content

Commit a63856c

Browse files
add context null check for built-in filters (#428)
1 parent 709bbeb commit a63856c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Microsoft.FeatureManagement/FeatureFilters/PercentageFilter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.Extensions.Configuration;
55
using Microsoft.Extensions.Logging;
66
using Microsoft.FeatureManagement.Utils;
7+
using System;
78
using System.Threading.Tasks;
89

910
namespace Microsoft.FeatureManagement.FeatureFilters
@@ -43,6 +44,11 @@ public object BindParameters(IConfiguration filterParameters)
4344
/// <returns>True if the feature is enabled, false otherwise.</returns>
4445
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context)
4546
{
47+
if (context == null)
48+
{
49+
throw new ArgumentNullException(nameof(context));
50+
}
51+
4652
//
4753
// Check if prebound settings available, otherwise bind from parameters.
4854
PercentageFilterSettings settings = (PercentageFilterSettings)context.Settings ?? (PercentageFilterSettings)BindParameters(context.Parameters);

src/Microsoft.FeatureManagement/FeatureFilters/TimeWindowFilter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public object BindParameters(IConfiguration filterParameters)
4343
/// <returns>True if the feature is enabled, false otherwise.</returns>
4444
public Task<bool> EvaluateAsync(FeatureFilterEvaluationContext context)
4545
{
46+
if (context == null)
47+
{
48+
throw new ArgumentNullException(nameof(context));
49+
}
50+
4651
//
4752
// Check if prebound settings available, otherwise bind from parameters.
4853
TimeWindowFilterSettings settings = (TimeWindowFilterSettings)context.Settings ?? (TimeWindowFilterSettings)BindParameters(context.Parameters);

0 commit comments

Comments
 (0)