Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore spacing chars for base64decode #32422

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/Base64/src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function read_until_end(pipe::Base64DecodePipe, ptr::Ptr{UInt8}, n::UInt)
end
end
consumed!(buffer, i)

return p
end

Expand Down Expand Up @@ -210,6 +209,7 @@ julia> String(b)
"""
function base64decode(s)
b = IOBuffer(s)
s = replace(s, r"\s" => "")
try
return read(Base64DecodePipe(b))
finally
Expand Down
11 changes: 11 additions & 0 deletions stdlib/Base64/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="""
const skipSpaces = """
TWFuIGlz IGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
IHNpbmd1b GFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
dGhlIG1pbmQs\nIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
ZSBzaG9ydCB2ZWh\n\nlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="""


@testset "Examples" begin
# Encode and decode
Expand Down Expand Up @@ -53,6 +60,10 @@ ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="""
ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76))
@test read(ipipe, String) == inputText

# Decode string containing invalid chars
ipipe = Base64DecodePipe(IOBuffer(skipSpaces))
@test read(ipipe, String) == inputText

# Decode with max line chars = 76 and no padding
#ipipe = Base64DecodePipe(IOBuffer(encodedMaxLine76[1:end-1]))
#@test read(ipipe, String) == inputText
Expand Down