From 6506fc91bdb85767cc26103679181ab02373f187 Mon Sep 17 00:00:00 2001 From: Jarvis Carroll Date: Tue, 23 Sep 2025 17:07:41 +1000 Subject: [PATCH] Also coerce unicode strings to FATE This is mainly so that gajudesk can pass text box content to hz as-is, but also allows users to pass utf8 binaries in, if they want to, for some reason. --- src/hz.erl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/hz.erl b/src/hz.erl index a15c75e..8215779 100644 --- a/src/hz.erl +++ b/src/hz.erl @@ -1850,6 +1850,18 @@ coerce({O, N, string}, Str, Direction) -> end; coerce({_, _, char}, Val, _Direction) when is_integer(Val) -> {ok, Val}; +coerce({O, N, char}, Str, to_fate) -> + Result = unicode:characters_to_list(Str), + case Result of + {error, _, _} -> + single_error({invalid, O, N, Str}); + {incomplete, _, _} -> + single_error({invalid, O, N, Str}); + [C] -> + {ok, C}; + _ -> + single_error({invalid, O, N, Str}) + end; coerce({O, N, {bytes, [Count]}}, Bytes, _Direction) when is_bitstring(Bytes) -> coerce_bytes(O, N, Count, Bytes); coerce({_, _, bits}, {bits, Num}, from_fate) -> @@ -2546,6 +2558,12 @@ coerce_char_test() -> {ok, Type} = annotate_type(char, #{}), try_coerce(Type, $?, $?). +coerce_unicode_test() -> + {ok, Type} = annotate_type(char, #{}), + % Latin Small Letter C with cedilla and acute + {ok, $ḉ} = coerce(Type, <<"ḉ"/utf8>>, to_fate), + ok. + %%% Complex AACI paramter and namespace tests