Skip to content

Strip whitespace when decoding -p base64 input #2507

@erhhung

Description

@erhhung

Describe the bug

# this fails :(
$ yq -n '{"foo":"bar"} | @yaml | @base64' | yq -p base64
Error: bad file '-': unexpected EOF

# this works!
$ yq -n '{"foo":"bar"} | @yaml' -o base64 | yq -p base64
foo: bar
# this also works!
$ yq -n '{"foo":"bar"} | @yaml | @base64' | yq '@base64d | @yamld'
foo: bar

# superficially same output
$ yq -n '{"foo":"bar"} | @yaml | @base64'
Zm9vOiBiYXIK
$ yq -n '{"foo":"bar"} | @yaml' -o base64
Zm9vOiBiYXIK

# but here's the culprit
$ yq -n '{"foo":"bar"} | @yaml | @base64' | wc -c
      13
$ yq -n '{"foo":"bar"} | @yaml' -o base64 | wc -c
      12
# extra line-feed!
$ yq -n '{"foo":"bar"} | @yaml | @base64' | xxd -p
5a6d39764f6942695958494b0a
$ yq -n '{"foo":"bar"} | @yaml' -o base64 | xxd -p
5a6d39764f6942695958494b

So, the parsing of base64-input via the -p base64 input format route should be more tolerant of extra whitespace. In fact, any whitespace, before, after, or in-between (fixed-length lines), should be ignored.

Version of yq: 4.48.1
Operating system: macOS
Installed via: Homebrew

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions