Fix: URL-encoded special characters in $filter and $orderby break OData parsing#3080
Fix: URL-encoded special characters in $filter and $orderby break OData parsing#3080
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>
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
@copilot, fix the above dotnet format errors. And check no more failures by running: |
…ards Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
Fixed in commit a78b348:
|
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
@copilot, look at test failures in the pipeline logs and fix them: |
I don't have access to the Azure DevOps pipeline logs (authentication required). Could you please paste the specific test failure messages or error output from the pipeline? I'll fix the issues once I can see what's failing. |
|
Read the logs from the attached file: |
…g book with % character instead Co-authored-by: Aniruddh25 <3513779+Aniruddh25@users.noreply.github.com>
Fixed in commit 4c5ed20. Root cause: Added books 22-25 broke existing tests expecting 21 books (7 test failures). Solution:
This avoids breaking unrelated tests while still validating the fix works correctly. |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Why make this change?
Users reported errors when filtering on strings containing special characters like ampersand (&). When using properly URL-encoded requests (e.g.,
?$filter=region eq 'filter %26 test'), DAB returns "unterminated string literal" errors instead of correctly processing the filter.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 parsing failures.What is this change?
Preserve URL encoding for OData parameters by extracting raw values before
ParseQueryString()decodes them:RawQueryStringproperty to store original encoded query stringRawQueryStringalongsideParsedQueryStringExtractRawQueryParameter()(internal static method) extracts encoded values by splitting on unencoded&separators%26has not been decoded to&&(parameter separators) while preserving encoded%26in valuesDataApiBuilderExceptionif parameter extraction fails unexpectedlyDatabase-agnostic: operates at HTTP parsing layer before any database-specific processing.
How was this tested?
FindTestWithFilterContainingSpecialCharacters: Tests$filterwith%character using existing book (SOME%CONN)FindTestWithOrderByContainingSpecialCharacters: Tests$orderbyURL encoding preservation?$filter=title%20eq%20%27SOME%25CONN%27,?$orderby=title%20desc) to test actual double-decoding bug scenarioExtractRawQueryParameter()directly (no reflection needed since method is internal)&,=,+,%,#,<,>,:,/,?Sample Request(s)
REST - Before (fails):
REST - After (succeeds):
Works with any URL-encoded special character in both
$filterand$orderby:%26(&),%3D(=),%2B(+),%25(%),%23(#),%3C(<),%3E(>),%3A(:),%2F(/),%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.