Skip to content

Commit

Permalink
PISTON-914: escape CAV comma/singlequote in originate strings (2600hz…
Browse files Browse the repository at this point in the history
…#6049)

- also encode JSON CAVs and give json_cav_ prefix
  • Loading branch information
danielfinke authored and jamesaimonetti committed Sep 26, 2019
1 parent d9da22b commit c8fbfc4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion applications/ecallmgr/src/ecallmgr_fs_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,21 @@ kazoo_var_to_fs_var_fold(K, V, Acc) ->

-spec kazoo_cavs_to_fs_vars_fold(kz_json:key(), kz_json:json_term(), iolist()) -> iolist().
kazoo_cavs_to_fs_vars_fold(K, V, Acc) ->
[list_to_binary([?APPLICATION_VAR_PREFIX, kz_term:to_list(K), "='", kz_term:to_list(V), "'"])
{Prefix, V1} = kazoo_cav_prefix_and_value(V),
[list_to_binary([Prefix, kz_term:to_list(K), "='", V1, "'"])
| Acc
].

-spec kazoo_cav_prefix_and_value(kz_json:json_term()) -> {string(), string()}.
kazoo_cav_prefix_and_value(V) ->
{Prefix, Encoded} = case kz_json:is_json_object(V) of
'true' -> {?JSON_APPLICATION_VAR_PREFIX, kz_json:encode(V)};
'false' -> {?APPLICATION_VAR_PREFIX, V}
end,
%% Escape all embedded single quotes and commas so that FS can consume them
Escaped = re:replace(Encoded, <<"([,'])">>, <<"\\\\\\g1">>, ['global', {'return', 'binary'}]),
{Prefix, kz_term:to_list(Escaped)}.

-spec codec_mappings(kz_term:ne_binary()) -> kz_term:ne_binary().
codec_mappings(<<"G722_32">>) ->
<<"G7221@32000h">>;
Expand Down

0 comments on commit c8fbfc4

Please sign in to comment.