[Bug]: Special characters in filter clause
What happened?
Tried filtering on the string "filter&test"
Original URL: https://localhost:5001/api/my_entity?$filter=Region eq 'filter&test' Encoded URL: https://localhost:5001/api/my_entity?$filter=Region+eq+%27filter%26test%27
I get this response when using the encoded URL: response: { "error": { "code": "BadRequest", "message": "There is an unterminated string literal at position 17 in 'Region eq 'filter'.", "status": 400 } }
Version
1.4.27
What database are you using?
Azure SQL
What hosting model are you using?
Local (including CLI)
Which API approach are you accessing DAB through?
REST
Relevant log output
Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: There is an unterminated string literal at position 17 in 'Region eq 'filter'.
---> Microsoft.OData.ODataException: There is an unterminated string literal at position 17 in 'Region eq 'filter'.
at Microsoft.OData.UriParser.ExpressionLexer.NextToken()
at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComparison()
at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalAnd()
at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalOr()
at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpression()
at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpressionText(String expressionText)
at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseFilter(String filter)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilterImplementation(String filter, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)
at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseFilter()
at Microsoft.OData.UriParser.ODataUriParser.ParseFilter()
at Azure.DataApiBuilder.Core.Parsers.ODataParser.GetFilterClause(String filterQueryString, String resourcePath, ODataUriResolver customResolver) in C:\Users\data-api-builder\src\Core\Parsers\FilterParser.cs:line 64
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Hi @HLaland,
Thank you for raising this issue. Would you try something?
Your URL:
https://localhost:5001/api/my_entity?$filter=Region+eq+%27filter%26test%27
This encoded form uses + for spaces:
Region+eq+%27filter%26test%27
[!WARNING] That’s form-url encoding (like
WebUtility.UrlEncode), not URI encoding. OData in Data API builder expects percent-encoded spaces (%20), not+.
Please try
Use Uri.EscapeDataString(...) instead of WebUtility.UrlEncode(...):
var filter = "Region eq 'filter&test'";
var url = $"https://localhost:5001/api/my_entity?$filter={Uri.EscapeDataString(filter)}";
This should produce:
$filter=Region%20eq%20%27filter%26test%27
[!NOTE] Please close this issue if this resolves your issue.
Hi @JerryNixon
I tried the percent encoding, but I am still getting the same error:
Hi @JerryNixon,
Any update on this?
Hi @JerryNixon
Any update on this?