Skip to content

Commit d1dc303

Browse files
authored
Merge pull request #181 from jimmyca15/user/jimmyca/nullCheck
Added null check validation for feature name.
2 parents 8b2722f + 8185bad commit d1dc303

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/Microsoft.FeatureManagement/DynamicFeatureManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ public async IAsyncEnumerable<string> GetDynamicFeatureNamesAsync([EnumeratorCan
4444

4545
public ValueTask<T> GetVariantAsync<T, TContext>(string feature, TContext appContext, CancellationToken cancellationToken)
4646
{
47+
if (string.IsNullOrEmpty(feature))
48+
{
49+
throw new ArgumentNullException(nameof(feature));
50+
}
51+
4752
return GetVariantAsync<T, TContext>(feature, appContext, true, cancellationToken);
4853
}
4954

5055
public ValueTask<T> GetVariantAsync<T>(string feature, CancellationToken cancellationToken)
5156
{
57+
if (string.IsNullOrEmpty(feature))
58+
{
59+
throw new ArgumentNullException(nameof(feature));
60+
}
61+
5262
return GetVariantAsync<T, object>(feature, null, false, cancellationToken);
5363
}
5464

src/Microsoft.FeatureManagement/FeatureManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ public FeatureManager(
4444

4545
public Task<bool> IsEnabledAsync(string feature, CancellationToken cancellationToken)
4646
{
47+
if (string.IsNullOrEmpty(feature))
48+
{
49+
throw new ArgumentNullException(nameof(feature));
50+
}
51+
4752
return IsEnabledAsync<object>(feature, null, false, cancellationToken);
4853
}
4954

5055
public Task<bool> IsEnabledAsync<TContext>(string feature, TContext appContext, CancellationToken cancellationToken)
5156
{
57+
if (string.IsNullOrEmpty(feature))
58+
{
59+
throw new ArgumentNullException(nameof(feature));
60+
}
61+
5262
return IsEnabledAsync(feature, appContext, true, cancellationToken);
5363
}
5464

src/Microsoft.FeatureManagement/Targeting/TargetingEvaluator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ public static bool IsTargeted(
115115
throw new ArgumentNullException(nameof(groups));
116116
}
117117

118+
if (string.IsNullOrEmpty(hint))
119+
{
120+
throw new ArgumentNullException(nameof(hint));
121+
}
122+
118123
string userId = ignoreCase ?
119124
targetingContext.UserId.ToLower() :
120125
targetingContext.UserId;
@@ -158,6 +163,11 @@ public static bool IsTargeted(
158163
throw new ArgumentNullException(nameof(targetingContext));
159164
}
160165

166+
if (string.IsNullOrEmpty(hint))
167+
{
168+
throw new ArgumentNullException(nameof(hint));
169+
}
170+
161171
string userId = ignoreCase ?
162172
targetingContext.UserId.ToLower() :
163173
targetingContext.UserId;

0 commit comments

Comments
 (0)