|
3 | 3 | using System.Linq; |
4 | 4 | using JsonApiDotNetCore.Configuration; |
5 | 5 | using JsonApiDotNetCore.Controllers; |
| 6 | +using JsonApiDotNetCore.Extensions; |
6 | 7 | using JsonApiDotNetCore.Internal; |
7 | 8 | using JsonApiDotNetCore.Internal.Query; |
8 | 9 | using JsonApiDotNetCore.Models; |
@@ -93,16 +94,16 @@ protected virtual List<FilterQuery> ParseFilterQuery(string key, string value) |
93 | 94 | // expected input = filter[id]=1 |
94 | 95 | // expected input = filter[id]=eq:1 |
95 | 96 | var queries = new List<FilterQuery>(); |
| 97 | + var openBracketIndex = key.IndexOf(OPEN_BRACKET); |
| 98 | + var closedBracketIndex = key.IndexOf(CLOSE_BRACKET); |
| 99 | + var propertyNameSlice = key.AsSpan().Slice(openBracketIndex + 1, closedBracketIndex - openBracketIndex - 1); |
| 100 | + var propertyName = propertyNameSlice.ToString(); |
96 | 101 |
|
97 | | - var propertyName = key.Split(OPEN_BRACKET, CLOSE_BRACKET)[1]; |
98 | | - |
99 | | - var values = value.Split(COMMA); |
100 | | - foreach (var val in values) |
| 102 | + var spanSplitter = new SpanSplitter(ref value, COMMA); |
| 103 | + for (var i = 0; i < spanSplitter.Count; i++) |
101 | 104 | { |
102 | | - (var operation, var filterValue) = ParseFilterOperation(val); |
103 | | - queries.Add(new FilterQuery(propertyName, filterValue, operation)); |
| 105 | + queries.Add(BuildFilterQuery(spanSplitter[i], propertyName)); |
104 | 106 | } |
105 | | - |
106 | 107 | return queries; |
107 | 108 | } |
108 | 109 |
|
@@ -235,5 +236,11 @@ protected virtual AttrAttribute GetAttribute(string propertyName) |
235 | 236 | throw new JsonApiException(400, $"Attribute '{propertyName}' does not exist on resource '{_controllerContext.RequestEntity.EntityName}'", e); |
236 | 237 | } |
237 | 238 | } |
| 239 | + |
| 240 | + private FilterQuery BuildFilterQuery(ReadOnlySpan<char> query, string propertyName) |
| 241 | + { |
| 242 | + var (operation, filterValue) = ParseFilterOperation(query.ToString()); |
| 243 | + return new FilterQuery(propertyName, filterValue, operation); |
| 244 | + } |
238 | 245 | } |
239 | 246 | } |
0 commit comments