Skip to content

Commit

Permalink
Issue erlang#8099: Accept empty list of binaries in binary:join/2 whi…
Browse files Browse the repository at this point in the history
…ch returns an empty binary
  • Loading branch information
onno-vos-dev committed Feb 8, 2024
1 parent 7319cdf commit 335d9fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/stdlib/src/binary.erl
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ _Example:_
""".
-doc(#{since => <<"OTP 27.0">>}).
-spec join([binary()], binary()) -> binary().
join([], _Separator) -> <<>>;
join([H], _Separator) -> H;
join([H | T], Separator) ->
join(T, Separator, H).
Expand Down
7 changes: 6 additions & 1 deletion lib/stdlib/test/binary_module_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ badargs(Config) when is_list(Config) ->
badarg = ?MASK_ERROR(binary:encode_hex(foo)),

badarg = ?MASK_ERROR(binary:join([<<"a">>], ", ")),
badarg = ?MASK_ERROR(binary:join([], <<",">>)),
badarg = ?MASK_ERROR(binary:join([""], <<",">>)),
badarg = ?MASK_ERROR(binary:join([123], <<",">>)),
badarg = ?MASK_ERROR(binary:join(123, <<",">>)),
badarg = ?MASK_ERROR(binary:join(#{}, <<",">>)),
badarg = ?MASK_ERROR(binary:join(foo, <<",">>)),
ok.

%% Whitebox test to force special trap conditions in
Expand Down Expand Up @@ -1588,6 +1592,7 @@ do_hex_roundtrip(Bytes) ->
join(Config) when is_list(Config) ->
<<"a, b, c">> = binary:join([<<"a">>, <<"b">>, <<"c">>], <<", ">>),
<<"a">> = binary:join([<<"a">>], <<", ">>),
<<>> = binary:join([], <<", ">>),
badarg = ?MASK_ERROR(binary:join([<<"a">>], ", ")),
badarg = ?MASK_ERROR(binary:join([], <<",">>)).

Expand Down

0 comments on commit 335d9fc

Please sign in to comment.