aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Bolinder <[email protected]>2018-09-17 10:33:29 +0200
committerHans Bolinder <[email protected]>2018-09-17 13:19:30 +0200
commit2d04d2bdf95c3a5f143ed2a5b9295fbf197b9b0b (patch)
treebc36d3788a8b1f1a877d94a6ebac9adfe8031d8c
parent82db62ab096cffd29c7afce6894eece14d5e1390 (diff)
downloadotp-2d04d2bdf95c3a5f143ed2a5b9295fbf197b9b0b.tar.gz
otp-2d04d2bdf95c3a5f143ed2a5b9295fbf197b9b0b.tar.bz2
otp-2d04d2bdf95c3a5f143ed2a5b9295fbf197b9b0b.zip
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.
-rw-r--r--lib/stdlib/src/io_lib_format.erl3
1 files changed, 2 insertions, 1 deletions
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});