From 4d821b3387d1ca98fd815344ce6ad68fe3788e50 Mon Sep 17 00:00:00 2001 From: "Dmitry A. Grechka" Date: Thu, 26 Jan 2023 19:50:47 +0600 Subject: [PATCH] Permitting any single word animal value. (supporting Bird value) (#9) --- .../Controllers/SolrProxyController.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CardIndexRestAPI/Controllers/SolrProxyController.cs b/CardIndexRestAPI/Controllers/SolrProxyController.cs index 117d381..b7ca275 100644 --- a/CardIndexRestAPI/Controllers/SolrProxyController.cs +++ b/CardIndexRestAPI/Controllers/SolrProxyController.cs @@ -216,12 +216,14 @@ public async Task MatchedImagesSearch([FromBody] GetMatchesRequest request) _ => throw new ArgumentException($"Unknown EventType: {request.EventType}") }; - string animalFilterTerm = request.Animal switch + // validation animal + var match = Regex.Match(request.Animal, @"^[A-Za-z]+$", RegexOptions.None); + if (!match.Success) { - "Cat" => "animal:Cat", - "Dog" => "animal:Dog", - _ => throw new ArgumentException($"Unknown Animal: {request.Animal}") - }; + throw new FormatException($"Animal field must contain A-Za-z characters only"); + } + + string animalFilterTerm = $"animal:{request.Animal}"; string cardTypeAndAnimalFilter = $"{typeFilterTerm} AND {animalFilterTerm}"; @@ -313,7 +315,7 @@ public async Task LatestCards([FromQuery]int maxCardsCount=10, [FromQuery] strin public async Task RecentCrawledStats([FromRoute] string cardsNamespace, [FromQuery] RecentStatsMode mode = RecentStatsMode.Days) { // checking input - var match = Regex.Match(cardsNamespace, @"^[0-9A-Za-z\-]+$", RegexOptions.IgnoreCase); + var match = Regex.Match(cardsNamespace, @"^[0-9A-Za-z\-]+$", RegexOptions.None); if (!match.Success) { throw new FormatException($"cardsNamespace must contain 0-9A-Za-z or '-' characters only"); @@ -332,9 +334,8 @@ public async Task RecentCrawledStats([FromRoute] string cardsNamespace, [FromQue _ => throw new NotSupportedException() }; - var safeCardsNamespace = cardsNamespace.Replace(Environment.NewLine, ""); - - Trace.TraceInformation($"Fetching statistics for ns \"{safeCardsNamespace}\" over recent {mode}(s)"); + var modeStr = mode.ToString(); + Trace.TraceInformation($"Fetching statistics for ns \"{cardsNamespace}\" over recent {modeStr}(s)"); Dictionary requestParams = new Dictionary(); requestParams.Add("q", "*:*");