Skip to content

Base64 base64decode does not ignore whitespace, but should #32397

Closed

Description

I'm not sure that there's actually anything in the RFC about this, but base64 strings often have newlines at regular intervals (GitHub for example sends file contents as 60-char lines).

julia> using Base64

julia> s = "bmFtZSA9ICJHZW5pZSIKdXVpZCA9ICJjNDNjNzM2ZS1hMmQxLTExZTgtMTYx\nZi1hZjk1MTE3ZmJkMWUiCmF1dGhvcnMgPSBbIkFkcmlhbiBTYWxjZWFudSA8\nZUBlc3NlbmNpYXJ5LmNvbT4iXQp2ZXJzaW9uID0gIjAuOS40IgoKW2RlcHNd\nCkFyZ1BhcnNlID0gImM3ZTQ2MGM2LTJmYjktNTNhOS04YzViLTE2ZjUzNTg1\nMWM2MyIKRGF0ZXMgPSAiYWRlMmNhNzAtMzg5MS01OTQ1LTk4ZmItZGMwOTk0\nMzJlMDZhIgpEaXN0cmlidXRlZCA9ICI4YmE4OWUyMC0yODVjLTViNmYtOTM1\nNy05NDcwMDUyMGVlMWIiCkd1bWJvID0gIjcwOGVjMzc1LWIzZDYtNWE1Ny1h\nN2NlLTgyNTdiZjk4NjU3YSIKSFRUUCA9ICJjZDNlYjAxNi0zNWZiLTUwOTQt\nOTI5Yi01NThhOTZmYWQ2ZjMiCkh0dHBDb21tb24gPSAiNzcxNzJjMWItMjAz\nZi01NGFjLWFhNTQtM2YxMTk4ZmU5ZjkwIgpKU09OID0gIjY4MmMwNmEwLWRl\nNmEtNTRhYi1hMTQyLWM4YjFjZjc5Y2RlNiIKTWFya2Rvd24gPSAiZDZmNDM3\nNmUtYWVmNS01MDVhLTk2YzEtOWMwMjczOTQ2MDdhIgpNYmVkVExTID0gIjcz\nOWJlNDI5LWJlYTgtNTE0MS05OTEzLWNjNzBlN2YzNzM2ZCIKTWlsbGJvYXJk\nID0gIjM5ZWMxNDQ3LWRmNDQtNWY0Yy1iZWFhLTg2NmYzMGI0ZDNiMiIKTWlu\naUxvZ2dpbmcgPSAiZjU5NDAyZWMtMDI2Mi01NzA3LWE1NjEtNzcwYWY5NGJj\nNWE2IgpOZXR0bGUgPSAiNDlkZWExZWUtZjZmYS01YWE2LTlhMTEtODgxNmNl\nZTdkNGI5IgpOdWxsYWJsZXMgPSAiNGQxZTFkNzctNjI1ZS01YjQwLTkxMTMt\nYTU2MGVjN2E4ZWNkIgpPcmRlcmVkQ29sbGVjdGlvbnMgPSAiYmFjNTU4ZTEt\nNWU3Mi01ZWJjLThmZWUtYWJlOGE0NjlmNTVkIgpQa2cgPSAiNDRjZmU5NWEt\nMWViMi01MmVhLWI2NzItZTJhZmRmNjliNzhmIgpSZWV4cG9ydCA9ICIxODlh\nMzg2Ny0zMDUwLTUyZGEtYTgzNi1lNjMwYmE5MGFiNjkiClJldmlzZSA9ICIy\nOTVhZjMwZi1lNGFkLTUzN2ItODk4My0wMDEyNmMyYTNhYmUiClNIQSA9ICJl\nYThlOTE5Yy0yNDNjLTUxYWYtODgyNS1hYWE2M2NkNzIxY2UiClNlcmlhbGl6\nYXRpb24gPSAiOWU4OGI0MmEtZjgyOS01YjBjLWJiZTktOWU5MjMxOTgxNjZi\nIgpTb2NrZXRzID0gIjY0NjJmZTBiLTI0ZGUtNTYzMS04Njk3LWRkOTQxZjkw\nZGVjYyIKVVJJUGFyc2VyID0gIjMwNTc4YjQ1LTlhZGMtNTk0Ni1iMjgzLTY0\nNWVjNDIwYWY2NyIKVW5pY29kZSA9ICI0ZWMwYTgzZS00OTNlLTUwZTItYjlh\nYy04ZjcyYWNmNWE4ZjUiCllBTUwgPSAiZGRiNmQ5MjgtMjg2OC01NzBmLWJk\nZGYtYWIzZjljZjk5ZWI2IgoKW2NvbXBhdF0KanVsaWEgPSAiMSIK"

julia> println(String(base64decode(s)))
name = "Genie"
uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e"
authors = ["Adrian Salceanu <e@essenciary.com>"]
version = "0.9.4"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Gumbo = "708ec375-b3d6-5a57-a7ce-8257bf98657a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
HttpCommon = "77172c1b-203f-54ac-aa54-3f1198fe9f90"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
MbedTLS = "739be429-bea8-5141-9913-cc70e7f3736d"
Millboard = "39ec1447-df44-5f4c-beaa-866f30b4d3b2"
MiniLogging = "f59402ec-0262-5707-a561-770af94bc5a6"
Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9"
Nullables = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
URIÄÄòser = "30578b45-9adc-5946-b283-645ec420af67"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
julia = "1"

URIÄÄòser is a pretty interesting way to spell URIParser.

Plugging that same string into Python's base64.b64decode works as expected.
Applying replace(s, r"\s" => "") before decoding works, but it shouldn't be necessary and probably performs less than optimally.

Discovered through debugging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorgood first issueIndicates a good issue for first-time contributors to Juliahelp wantedIndicates that a maintainer wants help on an issue or pull request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions