Skip to content

Cherry-Pick: Fix failure on REST requests with $filter and $orderby parameters#3673

Open
RubenCerna2079 wants to merge 1 commit into
release/2.0from
dev/rubencerna/cherry-pick-rest
Open

Cherry-Pick: Fix failure on REST requests with $filter and $orderby parameters#3673
RubenCerna2079 wants to merge 1 commit into
release/2.0from
dev/rubencerna/cherry-pick-rest

Conversation

@RubenCerna2079

Copy link
Copy Markdown
Contributor

Why make this change?

This change cherry-picks the PR that fixes the $filter and $orderby parameters

What is this change?

Cherry-picked PRs:

How was this tested?

Existing tests in cherry-pick cover new changes.

Sample Request(s)

N/A

)

## Why make this change?

- Fix issue #3662

This issue is caused by a regression in PR
#3080
The regression is that we start using the raw encoded URL and we assume
that the `$` character is not encoded when using the
`ExtractRawQueryParameter` function, this is half true, since depending
on where the URL comes from it will encode it or it will treat it as a
special character and leave it as it is.
This means the function looks for the `$filter` or `$orderby` when the
URL has the possibility to change them to `%24filter` or `%24orderby`
which causes the failure.

## What is this change?

This change fixes a bug that caused using `$filter` or `$orderby` in
REST. This is done by encoding the `parameterName` so that it has the
same format as the raw URL, it will only change it if it is unable to
find the original `$` character in the raw query.

## How was this tested?

- [ ] Integration Tests
- [x] Unit Tests
Added end to end test to ensure that REST requests that use `$filter`
and `$orderby` succeed for both cases where a user uses the special
character `$` or its URL encoded format `%24`.

## Sample Request(s)
http://localhost:5000/api/Book?$orderby=id desc
http://localhost:5000/api/Book?$filter=publisher_id 1234

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

Cherry-picks a fix to REST OData query parsing so $filter / $orderby work reliably whether the $ is present literally or URL-encoded as %24, and adds an end-to-end regression test to validate both forms.

Changes:

  • Update RequestParser.ExtractRawQueryParameter to fall back to an encoded parameter name when the raw query string doesn’t contain the unencoded key.
  • Add an MSSQL end-to-end REST test covering both $filter/$orderby and %24filter/%24orderby requests.

Reviewed changes

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

File Description
src/Core/Parsers/RequestParser.cs Adds fallback handling for URL-encoded query parameter names when extracting raw $filter/$orderby values.
src/Service.Tests/Configuration/ConfigurationTests.cs Adds an MSSQL end-to-end regression test for REST requests using $filter and $orderby in both encoded and unencoded forms.

/// options $filter and $orderby succeed to ensure no regression can occur.
/// </summary>
[DataTestMethod]
[DataRow("/api/Book?$orderby=id desc&$filter=publisher_id eq 1234", DisplayName = "REST URL without encoded characters")]
out RuntimeConfig deserializedConfig,
replacementSettings: new(),
connectionString: GetConnectionStringFromEnvironmentConfig(environment: TestCategory.MSSQL)));
string configFileName = "custom-config.json";
Comment on lines +325 to +329
// Encode the parameterName to ensure it matches the encoding in the query string if the $ sign is URL encoded.
if (!queryString.Contains(parameterName, StringComparison.OrdinalIgnoreCase))
{
parameterName = HttpUtility.UrlEncode(parameterName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Cherry-Pick: Fix failure on REST requests with $filter and $orderby parameters

4 participants