aboutsummaryrefslogtreecommitdiffstats
path: root/lib/diameter/src/base/diameter_types.erl
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2013-07-24 11:05:34 +0200
committerAnders Svensson <[email protected]>2013-07-30 17:56:53 +0200
commit8f69052ae8c27115f0cd1756e6949139759aa751 (patch)
tree9c2f02386fb75bd710f56d0c7d262d4abceb91ad /lib/diameter/src/base/diameter_types.erl
parent4c4cf7d15b5179808e7e614694113e47277fd22d (diff)
downloadotp-8f69052ae8c27115f0cd1756e6949139759aa751.tar.gz
otp-8f69052ae8c27115f0cd1756e6949139759aa751.tar.bz2
otp-8f69052ae8c27115f0cd1756e6949139759aa751.zip
Fix UTF8String encode
To accept any nested list of codepoints and binaries. A list containing a binary was previously misinterpreted and the documentation was incomplete. Also, rework codec suite slightly to be able to specify values for which decode o encode is the identity map, for which encode should succeed, and for which encode should fail.
Diffstat (limited to 'lib/diameter/src/base/diameter_types.erl')
-rw-r--r--lib/diameter/src/base/diameter_types.erl18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/diameter/src/base/diameter_types.erl b/lib/diameter/src/base/diameter_types.erl
index 9ae289034c..ab7a7f3549 100644
--- a/lib/diameter/src/base/diameter_types.erl
+++ b/lib/diameter/src/base/diameter_types.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -360,7 +360,7 @@ v6enc([], B) ->
'UTF8String'(M, []);
'UTF8String'(encode, S) ->
- uenc(S, []).
+ uenc(if is_binary(S) -> [S]; true -> S end, []).
udec(<<>>, Acc) ->
lists:reverse(Acc);
@@ -368,20 +368,20 @@ udec(<<>>, Acc) ->
udec(<<C/utf8, Rest/binary>>, Acc) ->
udec(Rest, [C | Acc]).
-uenc(E, Acc)
- when E == [];
- E == <<>> ->
+uenc([], Acc) ->
list_to_binary(lists:reverse(Acc));
-uenc(<<C/utf8, Rest/binary>>, Acc) ->
- uenc(Rest, [<<C/utf8>> | Acc]);
-
-uenc([[] | Rest], Acc) ->
+uenc([E | Rest], Acc)
+ when E == <<>>;
+ E == [] ->
uenc(Rest, Acc);
uenc([[H|T] | Rest], Acc) ->
uenc([H, T | Rest], Acc);
+uenc([<<C/utf8, T/binary>> | Rest], Acc) ->
+ uenc([C, T | Rest], Acc);
+
uenc([C | Rest], Acc) ->
uenc(Rest, [<<C/utf8>> | Acc]).