Skip to content

Commit

Permalink
Fix a NPE in Filter API
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Dec 3, 2023
1 parent 52ee489 commit b0e81f4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Shoko.Server/API/v3/Helpers/FilterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public FilterFactory(IHttpContextAccessor context, FilterEvaluator evaluator)

_expressionTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes())
.Where(a => a != typeof(FilterExpression) && !a.IsGenericType && typeof(FilterExpression).IsAssignableFrom(a) &&
!typeof(SortingExpression).IsAssignableFrom(a)).ToDictionary(a => a.Name.Replace("Expression", "").Replace("Function", ""));
!typeof(SortingExpression).IsAssignableFrom(a)).ToDictionary(a => a.Name.Replace("Expression", "").Replace("Function", "").Replace("Selector", ""));

_sortingTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes())
.Where(a => a != typeof(FilterExpression) && !a.IsAbstract && !a.IsGenericType && typeof(SortingExpression).IsAssignableFrom(a))
Expand Down Expand Up @@ -101,7 +101,7 @@ public Filter.FilterCondition GetExpressionTree(FilterExpression expression)
if (expression is null) return null;
var result = new Filter.FilterCondition
{
Type = expression.GetType().Name.Replace("Expression", "").Replace("Function", "")
Type = expression.GetType().Name.Replace("Expression", "").Replace("Function", "").Replace("Selector", "")
};

// Left/First
Expand Down Expand Up @@ -163,6 +163,7 @@ public Filter.FilterCondition GetExpressionTree(FilterExpression expression)

public FilterExpression<T> GetExpressionTree<T>(Filter.FilterCondition condition)
{
if (condition is null) return null;
if (!_expressionTypes.TryGetValue(condition.Type, out var type)) throw new ArgumentException($"FilterCondition type {condition.Type} was not found");
var result = (FilterExpression<T>)Activator.CreateInstance(type);

Expand Down

0 comments on commit b0e81f4

Please sign in to comment.