Skip to content

Commit 5c1fe02

Browse files
Merge pull request #3239 from rabbitmq/some-sort-of-unicode-support-in-env-files
Do not crash on badarg when env file has certain Unicode characters (cherry picked from commit 1596f03)
1 parent 123ca1f commit 5c1fe02

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

deps/rabbit_common/src/rabbit_env.erl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,14 +1653,17 @@ parse_conf_env_file_output2([Line | Lines], Vars) ->
16531653
end.
16541654

16551655
is_sh_set_x_output(Line) ->
1656-
re:run(Line, "^\\++ ", [{capture, none}]) =:= match.
1656+
UnicodeLine = unicode:characters_to_binary(Line),
1657+
re:run(UnicodeLine, "^\\++ ", [{capture, none}]) =:= match.
16571658

16581659
is_sh_function(_, []) ->
16591660
false;
16601661
is_sh_function(Line, Lines) ->
1661-
re:run(Line, "\\s\\(\\)\\s*$", [{capture, none}]) =:= match
1662+
UnicodeLine1 = unicode:characters_to_binary(Line),
1663+
UnicodeLine2 = unicode:characters_to_binary(hd(Lines)),
1664+
re:run(UnicodeLine1, "\\s\\(\\)\\s*$", [{capture, none}]) =:= match
16621665
andalso
1663-
re:run(hd(Lines), "^\\s*\\{\\s*$", [{capture, none}]) =:= match.
1666+
re:run(UnicodeLine2, "^\\s*\\{\\s*$", [{capture, none}]) =:= match.
16641667

16651668
parse_sh_literal("'" ++ SingleQuoted, Lines, Literal) ->
16661669
parse_single_quoted_literal(SingleQuoted, Lines, Literal);

deps/rabbit_common/test/rabbit_env_SUITE.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,15 @@ check_parse_conf_env_file_output(_) ->
10571057
)),
10581058
?assertEqual(
10591059
#{"UNQUOTED" => "a",
1060+
"UNICODE" => [43, 43, 32, 1550, 32],
10601061
"SINGLE_QUOTED" => "b",
10611062
"DOUBLE_QUOTED" => "c",
10621063
"SINGLE_DOLLAR" => "d"},
10631064
rabbit_env:parse_conf_env_file_output2(
1064-
["UNQUOTED=a",
1065+
%% a relatively rarely used Unicode character
1066+
["++ ؎ ",
1067+
"UNQUOTED=a",
1068+
"UNICODE='++ ؎ '",
10651069
"SINGLE_QUOTED='b'",
10661070
"DOUBLE_QUOTED=\"c\"",
10671071
"SINGLE_DOLLAR=$'d'"],

0 commit comments

Comments
 (0)