Skip to content

Fix failure on REST requests with $filter and $orderby parameters#3664

Open
RubenCerna2079 wants to merge 5 commits into
mainfrom
dev/rubencerna/fix-filter-bug
Open

Fix failure on REST requests with $filter and $orderby parameters#3664
RubenCerna2079 wants to merge 5 commits into
mainfrom
dev/rubencerna/fix-filter-bug

Conversation

@RubenCerna2079

@RubenCerna2079 RubenCerna2079 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Why make this change?

This issue is caused by a regression in PR #3080

What is this change?

This change fixes a bug that caused using $filter or $orderby in REST. This is done by replacing the URL-encoded special character into its counterpart as a '$' sign, which is what is expected for this sign to be inside the URL.

How was this tested?

  • Integration Tests
  • Unit Tests
    Added end to end test to ensure that REST requests that use $filter and $orderby succeed.

Sample Request(s)

http://localhost:5000/api/Book?$orderby=id desc
http://localhost:5000/api/Book?$filter=publisher_id 1234

@RubenCerna2079 RubenCerna2079 marked this pull request as ready for review June 12, 2026 18:41
Copilot AI review requested due to automatic review settings June 12, 2026 18:41
@RubenCerna2079 RubenCerna2079 changed the title Fix bug Fix failure on REST requests with $filter and $orderby parameters Jun 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses a REST regression (issue #3662) where OData system query options like $filter / $orderby could fail to be extracted from the query string, by normalizing URL-encoded $ (%24) before downstream parsing.

Changes:

  • Normalize %24 to $ in the REST request query string prior to parsing.
  • Add an end-to-end REST test to validate requests using $filter and $orderby succeed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Core/Services/RestService.cs Normalizes the raw query string so $-prefixed OData query options can be parsed reliably.
src/Service.Tests/Configuration/ConfigurationTests.cs Adds an end-to-end REST test to prevent regressions for $filter / $orderby query options.

Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Core/Services/RestService.cs Outdated

@souvikghosh04 souvikghosh04 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs some changes on parsing logic and additional tests assesrtion

using (HttpClient client = server.CreateClient())
{
// Act
using HttpRequestMessage restRequest = new(HttpMethod.Get, "/api/Book?$orderby=id desc&$filter=publisher_id eq 1234");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this explicitly tests the %24. the httpclient would internally normalize this, so this can pass with or without the fix. you might need to explicitly pass the encoded values in URI "/api/Book?%24orderby=id%20desc&%24filter=publisher_id%20eq%201234") and then do proper assertions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the whole point of the test is to make an end-to-end scenario with values that a user would use. Adding the encoded values directly would defeat that purpose and would not help us catch any possible regressions in the future. DAB should be able to encode these values by itself and not throw any errors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the intent is fair but partially justifiable. this test doesn't hit the fix's code path. HttpClient won't percent-encode $ (it's a legal sub-delimiter per RFC 3986), so Request.QueryString never contains %24 here, the Replace calls never fire. you can verify by reverting the fix and confirming the test still passes.

DAB is the server. it doesn't encode. it decodes what arrives on the wire. The regression is specifically when a client sends %24filter. the test must send the encoded form.

Suggestion: keep both as [DataRow] inputs: the current URI as a smoke test, plus a %24-encoded variant as the actual regression guard.

QueryString? query = GetHttpContext().Request.QueryString;
string queryString = query is null ? string.Empty : GetHttpContext().Request.QueryString.ToString();
string queryString = query is null ? string.Empty : GetHttpContext().Request.QueryString.ToString()
.Replace("?%24", "?$").Replace("&%24", "&$"); //Add replacement in order to ensure '$' sign is present as expected only for the case where it is after a '?' or '&' signs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be parsed using already available libraries instead of manually? we have something like this below context.RawQueryString = queryString; context.ParsedQueryString = HttpUtility.ParseQueryString(queryString); or using Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be solved/fixed at root level to ensure downstream usage of the querystring is already valid.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the trailing comment on RestService.cs:75 says what the code does but not why $ arrives URL-encoded in the first place, nor what PR #3080 changed that broke it. future readers will look at the Replace chain and have no idea whether they can remove it.

using HttpResponseMessage restResponse = await client.SendAsync(restRequest);

// Assert - Verify REST response
Assert.AreEqual(HttpStatusCode.OK, restResponse.StatusCode, "REST request to auto-generated entity should succeed");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only checks HttpStatusCode.OK. a regression where $filter is silently dropped would still return 200 with an unfiltered list. can we also assert that the response body contains the rows you expect (publisher_id == 1234 only) and in the order requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Regression Unable to extract $filter parameter from query string.

5 participants