Open osresearch opened 3 years ago
I define functions to work around.
def base64url: @base64 | gsub("\\+"; "-") | gsub("/"; "_") | gsub("="; "");
def base64urld: gsub("-"; "+") | gsub("_"; "/") | gsub("%3D"; "=") | @base64d;
Having a way to output the raw binary would be helpful, too. The @base64d does not output the two bytes 0xFF 0xFE, but instead does a UTF-8 expansion.
Binary supports seems working in this PR. https://github.com/stedolan/jq/pull/2314
@apstndb thanks, this helped me to create a jwt-decode
function:
~ » cat ~/.jq
def base64url: @base64 | gsub("\\+"; "-") | gsub("/"; "_") | gsub("="; "");
def base64urld: gsub("-"; "+") | gsub("_"; "/") | gsub("%3D"; "=") | @base64d;
~ » function jwt-decode () {
jq -R 'split(".") | .[1] | base64urld | fromjson'
}
Describe the bug Many programs output "web safe" or "filename safe" base64 (defined in RFC 4648 and called
base64url
). In this format the/
and+
characters are replaced with_
and-
, and the=
padding is often URI escaped with%3D
. The@base64d
string formatter does not handle this variant.To Reproduce
Expected behavior
Environment (please complete the following information):
Additional context Having a way to output the raw binary would be helpful, too. The
@base64d
does not output the two bytes0xFF 0xFE
, but instead does a UTF-8 expansion.