OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

Edm.Binary is not serialized according to RFC 4648 (and OData ABNF) Base64 string #1321

Open adzhiljano opened 6 years ago

adzhiljano commented 6 years ago

0x000000000010fac0 is serialized as AAAAAAAQ+sA= (notice the '+') which is not in sync with the OData ABNF (which describes the Base64 string according to RFC 4648). So when I try to do the query $filter=Version eq binary'AAAAAAAQ+sA=' I get The query specified in the URI is not valid. Unrecognized 'Edm.Binary' literal 'binary'AAAAAAAQ sA='' at '11' in 'Version eq binary'AAAAAAAQ sA=''. (notice that the '+' is replaced with ' ' in the error, because of: https://github.com/OData/odata.net/blob/962aa97d616b34243bbddc9c7bf6cead4a8fe275/src/Microsoft.OData.Core/UriParser/QueryOptionUtils.cs#L133

Assemblies affected

Microsoft.OData.Core version=7.5.0 Microsoft.AspNet.OData version=7.0.1

Reproduce steps

$filter=Version eq binary'AAAAAAAQ+sA='

Expected result

No parse errors

Actual result

The query specified in the URI is not valid. Unrecognized 'Edm.Binary' literal 'binary'AAAAAAAQ sA='' at '11' in 'Version eq binary'AAAAAAAQ sA=''.

Additional detail

As far as I can tell, the problem is that OData is using Convert.ToBase64String(value) https://github.com/OData/odata.net/blob/962aa97d616b34243bbddc9c7bf6cead4a8fe275/src/Microsoft.OData.Core/Json/JsonValueUtils.cs#L330 which is not in sync with RFC 4648 (notice the base64Table and that it contains '+' and '/', instead of '-' and '_')

A solution might be to do a manual replace like so: https://stackoverflow.com/a/26354677/6486414 or just use HttpServerUtility.UrlTokenEncode: https://referencesource.microsoft.com/#System.Web/Util/HttpEncoder.cs,856 which basically does the same

Keep in mind that in this issue my approach is to unify the Edm.Binary format in the url and request body, which might not be the target of the OData protocol. So, if the target is to have two different formats Convert.FromBase64String shouldn't be used to parse data from the URL because it is not in sync with RFC 4648.

biaol-odata commented 5 years ago

@mikepizzo would you please take a look to see whether it is by design or not? Thanks.

julealgon commented 3 years ago

Are there any updates here @biaol-odata ?

Esther-St commented 1 year ago

@biaol-odata I'm hitting this same issue, any update? any workaround?