From 2d04d2bdf95c3a5f143ed2a5b9295fbf197b9b0b Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 17 Sep 2018 10:33:29 +0200 Subject: stdlib: Allow lists with binaries in the Format argument As a consequence of some refactoring (OTP-14983, option 'chars_limit'), the Format argument of io_lib:format() no longer accepts binaries in lists in Erlang/OTP 21.0. Note that if Format is not of type io:format(), control sequences in Format are ignored. This can result in unpredictable behaviour if, for example, the output of io_lib:format() is used as Format: if the output happens to be a string(), then control sequences are interpreted, otherwise not. A check that Format is of type io:format() will likely be introduced in Erlang/OTP 22.0. That will probably mean work for some users, but considering how unpredictable io_lib:format() is, we should try to fix that. --- lib/stdlib/src/io_lib_format.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/stdlib') diff --git a/lib/stdlib/src/io_lib_format.erl b/lib/stdlib/src/io_lib_format.erl index e247b00a04..ab9031573b 100644 --- a/lib/stdlib/src/io_lib_format.erl +++ b/lib/stdlib/src/io_lib_format.erl @@ -246,7 +246,8 @@ count_small([#{control_char := $W}|Cs], #{w := W} = Cnts) -> count_small(Cs, Cnts#{w := W + 1}); count_small([#{control_char := $s}|Cs], #{w := W} = Cnts) -> count_small(Cs, Cnts#{w := W + 1}); -count_small([S|Cs], #{other := Other} = Cnts) when is_list(S) -> +count_small([S|Cs], #{other := Other} = Cnts) when is_list(S); + is_binary(S) -> count_small(Cs, Cnts#{other := Other + string:length(S)}); count_small([C|Cs], #{other := Other} = Cnts) when is_integer(C) -> count_small(Cs, Cnts#{other := Other + 1}); -- cgit v1.2.3