Skip to content

@base64d does not handle web-safe encoded base64 #2262

Description

@osresearch

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

$ echo '_-8%3D' | jq -R -r '@base64d'
jq: error (at <stdin>:1): string ("_-%3D") is not valid base64 data

Expected behavior

$ echo '_-8%3D' | jq -R -r '@base64d' | xxd -g1
00000000: ff ef

Environment (please complete the following information):

  • Ubuntu 20.04.
  • jq-1.6

Additional context
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions