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.
0x000000000010fac0
is serialized asAAAAAAAQ+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 getThe 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#L133Assemblies 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 sameKeep 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.