-
Notifications
You must be signed in to change notification settings - Fork 351
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
Decimal number incorrectly parsed by the lexer #461
Comments
@raffaeler How to parse the number has been a long discussion, the conclusion we achieve is we parse the number to the lowest precision type which does not lose any precision of passed in number, in this way, and for consumer, he can cast lower precision type to higher precision type. In the service logic of your code, you can cast the type to the type you need. Let's know if you have any other questions or comments, thanks, |
Casting would be the worst solution since doubles and floats are IEEE754 types which means loss of fidelity for the number. The other solution is to apply the "M" suffix but the v4 specs explicitly make it obsolete, therefore the only possible safe solution is to derive the type looking at the schema. |
Another reason for the cast being the wrong solution: |
|
The type deduction you are doing in the code is admirable but results also in spending a lot of time. With regards to my example, the filter example I posted do not work (the predicate result in a false condition). In the sample project the provider is entity framework (not true for the real project). In any case the solution to patch the literal number is not acceptable. It would mean to parse all the possible filters looking for literals. The real project is a framework, not a vertical custom solution, therefore the database is not known in advance. Thanks |
Move to backlog to see how the new reader and writer of OData 7.0 works for this. |
This seems to be an issue in ASPNETCORE.ODATA and there is already another issue tracking it. Closing this. |
@ElizabethOkerio I don't get why the other issue (opened just 23 days ago) was transferred and got "prevalence" over this one that is missing attention in 6 years (and still causes issues in large customer / corp.) |
I have a Product entity exposed via oData with a "Test" property of type "decimal".
Among the others, the database contains these values (just the Test column):
3234567890.1234
1234.1234
Query 1
http://localhost:61320/odata/Products?$filter=Test%20eq%203234567890.1234M
Succeed because of the "M" suffix (even if it is deprecated by v4 of the specs)
Query 2
http://localhost:61320/odata/Products?$filter=Test%20eq%203234567890.1234
The query fails. The number is intepreted as a double instead of a decimal
Query 3
http://localhost:61320/odata/Products?$filter=Test%20eq%201234.1234
The query succeed but it is just for luck because the parser recognize the number as a float.
The faulty method is "MakeBestGuessOnNoSuffixStr":
https://github.com/OData/odata.net/blob/bfd173fdda4cd2f377316ba80c392979e291dfed/src/Microsoft.OData.Core/UriParser/ExpressionLexer.cs
The following screenshot shows the faulty method returning a double instead of a decimal.
In the watch window you can see the method parameters as well as the current instruction pointer.
The bug appears also in the latest (current) nuget package.
This is just a repro of the bug reported in production.
The text was updated successfully, but these errors were encountered: