-
Notifications
You must be signed in to change notification settings - Fork 20
Description
In XQuery 3.1 there are two XDM types to represent binary values xs:base64binary and xs:hexBinary.
The current draft adds binary literals as an additional option.
Thus, it is possible to base64 encode any value by casting a xs:base64binary to a xs:string.
xs:base64Binary("+w==") => xs:string()There is no standard way to serialize those binary values to the URL safe variant of that encoding described in section 5 of RFC 4648.
The simplest workaround is replacing the unsafe characters of the alphabet (+ and /) and dropping the padding at the end with
xs:base64Binary("+w==") => translate("+/=", "-_")This of course will only work for relatively small binary values. In order for processors to offer a performant and efficient way I see several options.
- adding new type
xs:base64BinaryUrlSafewhose string representation uses the adapted alphabet with-and_and does not add padding at the end - a new function in fn namespace
fn:encode-base64-url-safe($data as (xs:string | xs:base64Binary | xs:hexBinary)) as xs:string - a new function in bin namespace
bin:encode-base64-url-safe($data as (xs:string | xs:base64Binary | xs:hexBinary)) as xs:string - add an output option that will serialize all binary values to base64 url-safe when cast to strings
Addendum
I am also wondering why binary values cannot be created from numeric literals. Especially now that we have the binary notation for integer literals and the xs:integer type is unbounded this would be a perfectly fine literal notation to create binary values from. At least as suitable as string literals that are currently allowed.
xs:hexBinary(0xfb) and xs:base64Binary(0b11111111)