ordercloud-api / ordercloud-dotnet-catalyst

A foundational library for OrderCloud integrations and server-side projects in .NET
Apache License 2.0
9 stars 15 forks source link

Multiple filter query string incorrectly generated #121

Closed moo2u2 closed 5 months ago

moo2u2 commented 6 months ago

Issue

When passing multiple filter values with the same name (in the query) an error response is returned.

Examples of when this may be needed are:

This is due to the fact that the value variable in ListArgsBinder.LoadFromQueryString() is actually a Microsoft.Extensions.Primitives.StringValues (ie can be multiple) but is treated like a string.

Steps to reproduce

  1. Create Product in OrderCloud with:
    • a numeric xp property (eg. testnumber with value of 2)
    • a text xp property (eg. author with value of test)
  2. Clone Headstart (or create your own API controller using Catalyst)
  3. Call /me/products?xp.testnumber=>1&xp.testnumber=<5 and observe the error
    {
    "Errors": [
        {
            "ErrorCode": "Search.InvalidQuery",
            "Message": "Query is invalid.",
            "Data": {
                "Reason": "Invalid input: \"1,<5\"."
            }
        }
    ]
    }
  4. Call /me/products?xp.author=test*&xp.author=!*user and debug the value of filters passed through to oc.Me.ListProductsAsync(): xp.author=test*,!*user which is not the expected value of xp.author=test*&xp.author=!*user

The same issue occurs (for the same reason) if the filters are instead passed through using a JSON body with property filters . Sample body:

{
  "filters": [
    {
      "propertyName": "xp.testnumber",
      "filterExpression": ">1"
    },
    {
      "propertyName": "xp.testnumber",
      "filterExpression": "<5"
    }
  ]
}