2424 context_to_code_path /1 ]).
2525
2626-ifdef (TEST ).
27- -export ([value_is_yes /1 ]).
27+ -export ([parse_conf_env_file_output2 /2 ,
28+ value_is_yes /1 ]).
2829-endif .
2930
3031-define (USED_ENV_VARS ,
@@ -1608,11 +1609,12 @@ parse_conf_env_file_output(Context, _, []) ->
16081609 Context ;
16091610parse_conf_env_file_output (Context , Marker , [Marker | Lines ]) ->
16101611 % % Found our marker, let's parse variables.
1611- parse_conf_env_file_output1 (Context , Lines , #{} );
1612+ parse_conf_env_file_output1 (Context , Lines );
16121613parse_conf_env_file_output (Context , Marker , [_ | Lines ]) ->
16131614 parse_conf_env_file_output (Context , Marker , Lines ).
16141615
1615- parse_conf_env_file_output1 (Context , [], Vars ) ->
1616+ parse_conf_env_file_output1 (Context , Lines ) ->
1617+ Vars = parse_conf_env_file_output2 (Lines , #{}),
16161618 % % Re-export variables.
16171619 lists :foreach (
16181620 fun (Var ) ->
@@ -1628,27 +1630,30 @@ parse_conf_env_file_output1(Context, [], Vars) ->
16281630 ok
16291631 end
16301632 end , lists :sort (maps :keys (Vars ))),
1631- Context ;
1632- parse_conf_env_file_output1 (Context , [Line | Lines ], Vars ) ->
1633+ Context .
1634+
1635+ parse_conf_env_file_output2 ([], Vars ) ->
1636+ Vars ;
1637+ parse_conf_env_file_output2 ([Line | Lines ], Vars ) ->
16331638 SetXOutput = is_sh_set_x_output (Line ),
16341639 ShFunction = is_sh_function (Line , Lines ),
16351640 if
16361641 SetXOutput ->
1637- parse_conf_env_file_output1 ( Context , Lines , Vars );
1642+ parse_conf_env_file_output2 ( Lines , Vars );
16381643 ShFunction ->
1639- skip_sh_function (Context , Lines , Vars );
1644+ skip_sh_function (Lines , Vars );
16401645 true ->
16411646 case string :split (Line , " =" ) of
16421647 [Var , IncompleteValue ] ->
1643- {Value , Lines1 } = parse_sh_literal (IncompleteValue , Lines ),
1648+ {Value , Lines1 } = parse_sh_literal (IncompleteValue , Lines , " " ),
16441649 Vars1 = Vars #{Var => Value },
1645- parse_conf_env_file_output1 ( Context , Lines1 , Vars1 );
1650+ parse_conf_env_file_output2 ( Lines1 , Vars1 );
16461651 _ ->
16471652 % % Parsing failed somehow.
16481653 rabbit_log_prelaunch :warning (
16491654 " Failed to parse $RABBITMQ_CONF_ENV_FILE output: ~p " ,
16501655 [Line ]),
1651- Context
1656+ #{}
16521657 end
16531658 end .
16541659
@@ -1662,16 +1667,18 @@ is_sh_function(Line, Lines) ->
16621667 andalso
16631668 re :run (hd (Lines ), " ^\\ s*\\ {\\ s*$" , [{capture , none }]) =:= match .
16641669
1665- parse_sh_literal (" '" ++ SingleQuoted , Lines ) ->
1666- parse_single_quoted_literal (SingleQuoted , Lines , " " );
1667- parse_sh_literal (" $'" ++ DollarSingleQuoted , Lines ) ->
1668- parse_dollar_single_quoted_literal (DollarSingleQuoted , Lines , " " );
1669- parse_sh_literal (Unquoted , Lines ) ->
1670- {Unquoted , Lines }.
1670+ parse_sh_literal (" '" ++ SingleQuoted , Lines , Literal ) ->
1671+ parse_single_quoted_literal (SingleQuoted , Lines , Literal );
1672+ parse_sh_literal (" \" " ++ DoubleQuoted , Lines , Literal ) ->
1673+ parse_double_quoted_literal (DoubleQuoted , Lines , Literal );
1674+ parse_sh_literal (" $'" ++ DollarSingleQuoted , Lines , Literal ) ->
1675+ parse_dollar_single_quoted_literal (DollarSingleQuoted , Lines , Literal );
1676+ parse_sh_literal (Unquoted , Lines , Literal ) ->
1677+ {lists :reverse (Literal ) ++ Unquoted , Lines }.
16711678
1672- parse_single_quoted_literal ([$' ], Lines , Literal ) ->
1679+ parse_single_quoted_literal ([$' | Rest ], Lines , Literal ) ->
16731680 % % We reached the closing single quote.
1674- { lists : reverse ( Literal ) , Lines } ;
1681+ parse_sh_literal ( Rest , Lines , Literal ) ;
16751682parse_single_quoted_literal ([], [Line | Lines ], Literal ) ->
16761683 % % We reached the end of line before finding the closing single
16771684 % % quote. The literal continues on the next line and includes that
@@ -1680,6 +1687,17 @@ parse_single_quoted_literal([], [Line | Lines], Literal) ->
16801687parse_single_quoted_literal ([C | Rest ], Lines , Literal ) ->
16811688 parse_single_quoted_literal (Rest , Lines , [C | Literal ]).
16821689
1690+ parse_double_quoted_literal ([$" | Rest ], Lines , Literal ) ->
1691+ % % We reached the closing double quote.
1692+ parse_sh_literal (Rest , Lines , Literal );
1693+ parse_double_quoted_literal ([], [Line | Lines ], Literal ) ->
1694+ % % We reached the end of line before finding the closing double
1695+ % % quote. The literal continues on the next line and includes that
1696+ % % newline character.
1697+ parse_double_quoted_literal (Line , Lines , [$\n | Literal ]);
1698+ parse_double_quoted_literal ([C | Rest ], Lines , Literal ) ->
1699+ parse_double_quoted_literal (Rest , Lines , [C | Literal ]).
1700+
16831701parse_dollar_single_quoted_literal ([$' ], Lines , Literal ) ->
16841702 % % We reached the closing single quote.
16851703 {lists :reverse (Literal ), Lines };
@@ -1691,10 +1709,10 @@ parse_dollar_single_quoted_literal([], [Line | Lines], Literal) ->
16911709parse_dollar_single_quoted_literal ([C | Rest ], Lines , Literal ) ->
16921710 parse_dollar_single_quoted_literal (Rest , Lines , [C | Literal ]).
16931711
1694- skip_sh_function (Context , [" }" | Lines ], Vars ) ->
1695- parse_conf_env_file_output1 ( Context , Lines , Vars );
1696- skip_sh_function (Context , [_ | Lines ], Vars ) ->
1697- skip_sh_function (Context , Lines , Vars ).
1712+ skip_sh_function ([" }" | Lines ], Vars ) ->
1713+ parse_conf_env_file_output2 ( Lines , Vars );
1714+ skip_sh_function ([_ | Lines ], Vars ) ->
1715+ skip_sh_function (Lines , Vars ).
16981716
16991717% % -------------------------------------------------------------------
17001718% % Helpers.
0 commit comments