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:17:29 UTC

[couchdb] branch fix-comment-parsing-in-config updated (21c421d2f -> 22322c7bb)

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


 discard 21c421d2f Fix the ability to use ; in config values
     new 22322c7bb Fix the ability to use ; in config values

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (21c421d2f)
            \
             N -- N -- N   refs/heads/fix-comment-parsing-in-config (22322c7bb)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 src/config/src/config.erl | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)


[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 22322c7bbe9536c149d3bc31d041d7f1bbcd38dc
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 preceded by a
    space or a tab character.
    
    Fixes: https://github.com/apache/couchdb/issues/4651
---
 src/config/src/config.erl | 40 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/config/src/config.erl b/src/config/src/config.erl
index 72dff72d8..cf8c44835 100644
--- a/src/config/src/config.erl
+++ b/src/config/src/config.erl
@@ -480,8 +480,16 @@ 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
+            "";
+        NoLeadingComment when is_list(NoLeadingComment) ->
+            % Check for in-line comments. In-line comments must be preceded by
+            % space or a tab character.
+            [NoComments | _] = re:split(NoLeadingComment, " ;|\t;", [{return, list}]),
+            NoComments
+    end.
 
 % Specially handle the ?DELETE marker
 %
@@ -650,6 +658,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 +693,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(