base64:decode trailing whitespace patch for otp_src_R13B/lib/stdlib/src/base64.erl

View: New views
3 Messages — Rating Filter:   Alert me  

base64:decode trailing whitespace patch for otp_src_R13B/lib/stdlib/src/base64.erl

by Christopher Stelma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Trailing whitespace (after "=") is stripped, but the return value from
base64:strip_spaces is not in the same format expected by
base64:decode.

example of the problem:

------------------------------
----------------------------------------
3> base64:decode("cXV1eA==").
<<"quux">>
4> base64:decode("cXV1eA==\n").
** exception error: no function clause matching base64:decode([61,"=Ae1VXc"],

{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,

-1,-1,-1,-1,-1,-1,-1,-1,...},
                                                              [])
    in function  base64:decode/1
----------------------------------------------------------------------

more specifically to the internal api:
----------------------------------------------------------------------
7> base64:strip_spaces("foo==\n", []).
[61,"=oof"]
8> base64:strip_spaces("foo==", []).
"==oof"
----------------------------------------------------------------------

patch attached.


--
Christopher Stelma
chris@...

[base64fix.diff]

--- otp_src_R13B/lib/stdlib/src/base64.erl 2009-03-12 08:21:37.000000000 -0400
+++ otp_src_R13B-base64fix/lib/stdlib/src/base64.erl 2009-04-17 12:46:12.000000000 -0400
@@ -189,7 +189,7 @@
 %%%========================================================================
 
 strip_spaces([], A) -> A;
-strip_spaces([$=,C|_], A) when C =/= $= -> [$=, A];
+strip_spaces([$=,C|_], A) when C =/= $= -> [$= | A];
 strip_spaces([$\s|Cs], A) -> strip_spaces(Cs, A);
 strip_spaces([$\t|Cs], A) -> strip_spaces(Cs, A);
 strip_spaces([$\r|Cs], A) -> strip_spaces(Cs, A);


_______________________________________________
erlang-patches mailing list
erlang-patches@...
http://www.erlang.org/mailman/listinfo/erlang-patches

Re: base64:decode trailing whitespace patch for otp_src_R13B/lib/stdlib/src/base64.erl

by Igor Goryachev-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Christopher Stelma <chris@...> writes:

> Trailing whitespace (after "=") is stripped, but the return value from
> base64:strip_spaces is not in the same format expected by
> base64:decode.
>
> example of the problem:
>
> ----------------------------------------------------------------------
> 3> base64:decode("cXV1eA==").
> <<"quux">>
> 4> base64:decode("cXV1eA==\n").
> ** exception error: no function clause matching
> base64:decode([61,"=Ae1VXc"],
>
> {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
>
> -1,-1,-1,-1,-1,-1,-1,-1,...},
>                                                               [])
>     in function  base64:decode/1
> ----------------------------------------------------------------------

Hello, Christopher!

Doesn't base64:mime_decode/1 make deal?

% erl
Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] [async-threads:0] [kernel-poll:false]

Eshell V5.6.3  (abort with ^G)
1> base64:mime_decode("cXV1eA==\n").
<<"quux">>
2>


--
Igor Goryachev
Yandex development team.
_______________________________________________
erlang-patches mailing list
erlang-patches@...
http://www.erlang.org/mailman/listinfo/erlang-patches

Re: base64:decode trailing whitespace patch for otp_src_R13B/lib/stdlib/src/base64.erl

by Christopher Stelma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

mime_decode does work in this case, but it strips other characters as well.

The return value from one case in strip_spaces is not in the correct format.  It returns a list of two elements, $= and a string, [$=, A] instead of concatenating and returning a single string [$= | A].  This is the format returned by the strip function for mime_decode, but it removes other characters as well, which may not be correct for every use case.

On Mon, Apr 27, 2009 at 12:10 PM, Igor Goryachev <goryachev@...> wrote:
Christopher Stelma <chris@...> writes:

> Trailing whitespace (after "=") is stripped, but the return value from
> base64:strip_spaces is not in the same format expected by
> base64:decode.
>
> example of the problem:
>
> ----------------------------------------------------------------------
> 3> base64:decode("cXV1eA==").
> <<"quux">>
> 4> base64:decode("cXV1eA==\n").
> ** exception error: no function clause matching
> base64:decode([61,"=Ae1VXc"],
>
> {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
>
> -1,-1,-1,-1,-1,-1,-1,-1,...},
>                                                               [])
>     in function  base64:decode/1
> ----------------------------------------------------------------------

Hello, Christopher!

Doesn't base64:mime_decode/1 make deal?

% erl
Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] [async-threads:0] [kernel-poll:false]

Eshell V5.6.3  (abort with ^G)
1> base64:mime_decode("cXV1eA==\n").
<<"quux">>
2>


--
Igor Goryachev
Yandex development team.



--
Christopher Stelma
chris@...

_______________________________________________
erlang-patches mailing list
erlang-patches@...
http://www.erlang.org/mailman/listinfo/erlang-patches