-
Notifications
You must be signed in to change notification settings - Fork 301
Fix: URL-encoded special characters in $filter and $orderby break OData parsing #3080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
…ocumentation Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
Co-authored-by: JerryNixon <1749983+JerryNixon@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical bug where URL-encoded special characters in $filter and $orderby query parameters were being double-decoded, causing OData parsing failures. The issue occurred because HttpUtility.ParseQueryString() decodes parameter values before they reach the OData parser, which also expects to decode them.
Changes:
- Added
RawQueryStringproperty to preserve URL-encoded query strings before decoding - Modified
$filterand$orderbyparsing to use raw (URL-encoded) values instead of decoded values - Added comprehensive unit and integration tests across all supported database types
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Core/Models/RestRequestContexts/RestRequestContext.cs | Added RawQueryString property to store the URL-encoded query string |
| src/Core/Services/RestService.cs | Populated RawQueryString before parsing query parameters |
| src/Core/Parsers/RequestParser.cs | Added ExtractRawQueryParameter() method and modified $filter/$orderby parsing to use raw values |
| src/Service.Tests/UnitTests/RequestParserUnitTests.cs | Added 14 unit tests validating URL encoding preservation in various scenarios |
| src/Service.Tests/SqlTests/RestApiTests/Find/*.cs | Added integration tests for all database types (MsSql, PostgreSQL, MySQL, DwSql) |
| src/Service.Tests/DatabaseSchema-*.sql | Added test data with special characters for integration tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Why make this change?
HttpUtility.ParseQueryString()decodes query parameter values, causing double-decoding when DAB constructs OData filter strings. A URL like?$filter=title eq 'A %26 B'becomestitle eq 'A & B', where the literal&is interpreted as a query parameter separator, truncating the filter totitle eq 'Aand producing "unterminated string literal" errors.What is this change?
Preserve URL encoding for OData parameters by extracting raw values before
ParseQueryString()decodes them:RawQueryStringproperty to store original encoded queryRawQueryStringalongsideParsedQueryStringExtractRawQueryParameter()extracts encoded values by splitting on unencoded&separatorsDatabase-agnostic: operates at HTTP parsing layer before any DB-specific processing.
How was this tested?
Sample Request(s)
REST - Before (fails):
REST - After (succeeds):
Works with any URL-encoded special character:
%26(&),%3D(=),%3F(?), etc.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.