nickva commented on code in PR #4287:
URL: https://github.com/apache/couchdb/pull/4287#discussion_r1038896038


##########
src/config/src/config.erl:
##########
@@ -414,89 +415,73 @@ is_sensitive(Section, Key) ->
     end.
 
 parse_ini_file(IniFile) ->
+    IniBin = read_ini_file(IniFile),
+    ParsedIniValues = parse_ini(IniBin),
+    {ok, lists:filter(fun delete_keys/1, ParsedIniValues)}.
+
+parse_ini(IniBin) when is_binary(IniBin) ->
+    Lines0 = re:split(IniBin, "\r\n|\n|\r|\032", [{return, list}]),
+    Lines1 = lists:map(fun remove_comments/1, Lines0),
+    Lines2 = lists:map(fun trim/1, Lines1),
+    Lines3 = lists:filter(fun(Line) -> Line =/= "" end, Lines2),
+    {_, IniValues} = lists:foldl(fun parse_fold/2, {"", []}, Lines3),
+    lists:reverse(IniValues).
+
+parse_fold("[" ++ Rest, {Section, KVs}) ->
+    % Check for end ] brackend, if not found or empty section skip the rest
+    case string:split(Rest, "]") of
+        ["", _] -> {Section, KVs};
+        [NewSection, ""] -> {NewSection, KVs};
+        _Else -> {Section, KVs}
+    end;
+parse_fold(_Line, {"" = Section, KVs}) ->
+    % Empty section don't parse any lines until we're in a section
+    {Section, KVs};
+parse_fold(Line, {Section, KVs}) ->
+    case string:split(Line, " = ") of

Review Comment:
   Good idea! Added mentions to docs and default ini jwt_keys section. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to