Skip to content

Commit 6f6d116

Browse files
committed
xmerl: Fix xmerl_ucs:is_incharset/2 crash on multi-character lists
1 parent 701f00c commit 6f6d116

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/xmerl/src/xmerl_ucs.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ is_incharset(In,Charset) when is_list(In) ->
562562
{error,unsupported_charset};
563563
{error,_} ->
564564
false;
565-
[Int] when is_integer(Int) ->
565+
L when is_list(L) ->
566566
true
567567
end.
568568

lib/xmerl/test/xmerl_SUITE.erl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ all() ->
4646
[doctests,
4747
{group, cpd_tests}, xpath_text1, xpath_main,
4848
xpath_abbreviated_syntax, xpath_functions, xpath_relational,
49-
xpath_namespaces,
49+
xpath_namespaces, ucs_is_incharset,
5050
{group, misc}, {group, eventp_tests},
5151
{group, ticket_tests}, {group, app_test},
5252
{group, appup_test}, {group, format_test}].
@@ -678,6 +678,16 @@ allow_entities_test(Config) ->
678678
(catch xmerl_scan:file(File, [{allow_entities, false}])),
679679
ok.
680680

681+
%% Regression: xmerl_ucs:is_incharset/2 crashed with a case_clause on a
682+
%% multi-character list for charsets handled via to_unicode/2 (e.g. utf-8),
683+
%% because the clause only matched a single-element result.
684+
ucs_is_incharset(_Config) ->
685+
true = xmerl_ucs:is_incharset("abc", 'utf-8'),
686+
true = xmerl_ucs:is_incharset("a", 'utf-8'),
687+
true = xmerl_ucs:is_incharset("abc", 'iso-8859-1'),
688+
false = xmerl_ucs:is_incharset([256, 257], 'iso-8859-1'),
689+
ok.
690+
681691
%%======================================================================
682692
%% Support Functions
683693
%%======================================================================

0 commit comments

Comments
 (0)