From 8f69052ae8c27115f0cd1756e6949139759aa751 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Wed, 24 Jul 2013 11:05:34 +0200 Subject: 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. --- lib/diameter/src/base/diameter_types.erl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'lib/diameter/src/base') 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(<>, Acc) -> udec(Rest, [C | Acc]). -uenc(E, Acc) - when E == []; - E == <<>> -> +uenc([], Acc) -> list_to_binary(lists:reverse(Acc)); -uenc(<>, Acc) -> - uenc(Rest, [<> | 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([<> | Rest], Acc) -> + uenc([C, T | Rest], Acc); + uenc([C | Rest], Acc) -> uenc(Rest, [<> | Acc]). -- cgit v1.2.3