From 2399aba67d2e50318f7f7cbd22af04dc2b9eadea Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sat, 25 Oct 2014 02:05:02 +0200 Subject: [PATCH] Accept trailing whitespace in Base64 strings --- src/jlib.erl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/jlib.erl b/src/jlib.erl index 7735d7dbc..be1da3fd0 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -798,7 +798,12 @@ base64_to_term(Base64) -> -spec decode_base64(binary()) -> binary(). decode_base64(S) -> - decode_base64_bin(S, <<>>). + case catch binary:last(S) of + C when C == $\n; C == $\s -> + decode_base64(binary:part(S, 0, byte_size(S) - 1)); + _ -> + decode_base64_bin(S, <<>>) + end. take_without_spaces(Bin, Count) -> take_without_spaces(Bin, Count, <<>>).