You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2023/06/22 20:13:26 UTC

[couchdb] branch fix-comment-parsing-in-config created (now 0e174623a)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch fix-comment-parsing-in-config
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 0e174623a Fix the ability to use ; in config values

This branch includes the following new commits:

     new 0e174623a Fix the ability to use ; in config values

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Fix the ability to use ; in config values

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch fix-comment-parsing-in-config
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0e174623a152ab2ee29b42b42a061b2bfcacf38a
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Thu Jun 22 16:08:36 2023 -0400

    Fix the ability to use ; in config values
    
    Config values may contain `;` in them as long as `;` is not preceeded by a
    space or a tab character.
    
    Fixes: https://github.com/apache/couchdb/issues/4651
---
 src/config/src/config.erl | 42 +++++++++++++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/src/config/src/config.erl b/src/config/src/config.erl
index 72dff72d8..1f8ee2cab 100644
--- a/src/config/src/config.erl
+++ b/src/config/src/config.erl
@@ -480,8 +480,18 @@ read_ini_file(IniFile) ->
     end.
 
 remove_comments(Line) ->
-    {NoComments, _Comments} = string:take(Line, [$;], true),
-    NoComments.
+    case trim(Line) of
+        [$; | _] ->
+            % Comment is at the start of line after it's trimmed
+
+            % empty line will be removed in a filter function later
+            "";
+        NoLeadingComment when is_list(NoLeadingComment) ->
+            % Comment may be in-line. However, only consider it a comment if preceeded
+            % by a space or a tab as some values may have ; separated parts
+            [NoComments | _] = re:split(NoLeadingComment, " ;|\t;", [{return, list}]),
+            NoComments
+    end.
 
 % Specially handle the ?DELETE marker
 %
@@ -650,6 +660,10 @@ parse_skip_test() ->
     ?assertEqual([], ini("s]\nk=v")),
     ?assertEqual([], ini(";[s]\nk = v")),
     ?assertEqual([], ini(" ; [s]\nk = v")),
+    ?assertEqual([], ini("[s]\n ;k = v")),
+    ?assertEqual([], ini("[s]\n;;k = v")),
+    ?assertEqual([], ini("[s]\n\t;k = v")),
+    ?assertEqual([], ini("[s]\nk ;=v")),
     ?assertEqual([], ini("[s]\n ; k = v")),
     ?assertEqual([], ini("[]\nk = v")),
     ?assertEqual([], ini(";[s]\n ")).
@@ -681,14 +695,32 @@ parse_extra_equal_sign_test() ->
 
 parse_delete_test() ->
     ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk=")),
-    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk=;")),
     ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk =")),
     ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk = ")),
     ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk= ")),
     ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk = ")),
     ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk = ;")),
-    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk  =;")),
-    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk=\n")).
+    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk  =\t;")),
+    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk=\n")),
+    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk = ; ;")),
+    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk = ;v")),
+    ?assertEqual([{{"s", "k"}, ?DELETE}], ini("[s]\nk = ;")).
+
+parse_comments_test() ->
+    ?assertEqual([], ini("[s]\n;k=v")),
+    ?assertEqual([{{"s", "k"}, ";"}], ini("[s]\nk=;")),
+    ?assertEqual([{{"s", "k"}, ";"}], ini("[s]\nk =;")),
+    ?assertEqual([{{"s", "k"}, "v;"}], ini("[s]\nk = v;")),
+    ?assertEqual([{{"s", "k"}, ";v;"}], ini("[s]\nk =;v;")),
+    ?assertEqual([{{"s", "k"}, ";v"}], ini("[s]\nk =;v")),
+    ?assertEqual([{{"s", "k"}, "v;"}], ini("[s]\nk =v;")),
+    ?assertEqual([{{"s", "k"}, "v;;"}], ini("[s]\nk =v;;")),
+    ?assertEqual([{{"s", "k"}, "v1;v2"}], ini("[s]\nk = v1;v2")),
+    ?assertEqual([{{"s", "k"}, "v1;v2;v3"}], ini("[s]\nk = v1;v2;v3")),
+    ?assertEqual([{{"s", "k"}, "v1;v2"}], ini("[s]\nk = v1;v2 ;")),
+    ?assertEqual([{{"s", "k"}, "v1;v2"}], ini("[s]\nk = v1;v2\t;")),
+    ?assertEqual([{{"s", "k"}, "v1;v2"}], ini("[s]\nk = v1;v2 ;;")),
+    ?assertEqual([{{"s", "k"}, "v1;v2"}], ini("[s]\nk = v1;v2 ;c1; c2")).
 
 parse_multiple_kvs_test() ->
     ?assertEqual(