couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikewall...@apache.org
Subject config commit: updated refs/heads/2708-stronger-testing-for-config-set to 1e454a7
Date Tue, 09 Jun 2015 16:21:27 GMT
Repository: couchdb-config
Updated Branches:
  refs/heads/2708-stronger-testing-for-config-set ee652d2ee -> 1e454a724


Allow all printable unicode characters

Relax config:assert_string/1 such that all printable unicode
characters are allowed and add the appropropriate support
throughout the module.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-config/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-config/commit/1e454a72
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-config/tree/1e454a72
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-config/diff/1e454a72

Branch: refs/heads/2708-stronger-testing-for-config-set
Commit: 1e454a7246b3ab5d663db5e65fae9ac9571d14dc
Parents: ee652d2
Author: Mike Wallace <mikewallace@apache.org>
Authored: Tue Jun 9 17:08:07 2015 +0100
Committer: Mike Wallace <mikewallace@apache.org>
Committed: Tue Jun 9 17:08:07 2015 +0100

----------------------------------------------------------------------
 src/config.erl                   | 12 +++++------
 src/config_writer.erl            |  9 +++++---
 test/config_tests.erl            | 40 ++++++++++++++++++++++++++++++++++-
 test/fixtures/config_tests_2.ini |  1 +
 4 files changed, 52 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/1e454a72/src/config.erl
----------------------------------------------------------------------
diff --git a/src/config.erl b/src/config.erl
index 908dee7..f8c41c6 100644
--- a/src/config.erl
+++ b/src/config.erl
@@ -189,7 +189,7 @@ delete(Section, Key, Persist, Reason) when is_boolean(Persist) ->
     gen_server:call(?MODULE, {delete, Section, Key, Persist, Reason}).
 
 assert_string(Term) ->
-    case io_lib:printable_list(Term) of
+    case io_lib:printable_unicode_list(Term) of
         true ->
             ok;
         false ->
@@ -313,12 +313,12 @@ parse_ini_file(IniFile) ->
             throw({startup_error, Msg})
     end,
 
-    Lines = re:split(IniBin, "\r\n|\n|\r|\032", [{return, list}]),
+    Lines = re:split(IniBin, "\r\n|\n|\r|\032", [{return, list}, unicode]),
     {_, ParsedIniValues} =
     lists:foldl(fun(Line, {AccSectionName, AccValues}) ->
             case string:strip(Line) of
             "[" ++ Rest ->
-                case re:split(Rest, "\\]", [{return, list}]) of
+                case re:split(Rest, "\\]", [{return, list}, unicode]) of
                 [NewSectionName, ""] ->
                     {NewSectionName, AccValues};
                 _Else -> % end bracket not at end, ignore this line
@@ -327,7 +327,7 @@ parse_ini_file(IniFile) ->
             ";" ++ _Comment ->
                 {AccSectionName, AccValues};
             Line2 ->
-                case re:split(Line2, "\s?=\s?", [{return, list}]) of
+                case re:split(Line2, "\s?=\s?", [{return, list}, unicode]) of
                 [Value] ->
                     MultiLineValuePart = case re:run(Line, "^ \\S", []) of
                     {match, _} ->
@@ -338,7 +338,7 @@ parse_ini_file(IniFile) ->
                     case {MultiLineValuePart, AccValues} of
                     {true, [{{_, ValueName}, PrevValue} | AccValuesRest]} ->
                         % remove comment
-                        case re:split(Value, " ;|\t;", [{return, list}]) of
+                        case re:split(Value, " ;|\t;", [{return, list}, unicode]) of
                         [[]] ->
                             % empty line
                             {AccSectionName, AccValues};
@@ -355,7 +355,7 @@ parse_ini_file(IniFile) ->
                 [ValueName|LineValues] -> % yeehaw, got a line!
                     RemainingLine = config_util:implode(LineValues, "="),
                     % removes comments
-                    case re:split(RemainingLine, " ;|\t;", [{return, list}]) of
+                    case re:split(RemainingLine, " ;|\t;", [{return, list}, unicode]) of
                     [[]] ->
                         % empty line means delete this key
                         ets:delete(?MODULE, {AccSectionName, ValueName}),

http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/1e454a72/src/config_writer.erl
----------------------------------------------------------------------
diff --git a/src/config_writer.erl b/src/config_writer.erl
index 2812686..56f1d54 100644
--- a/src/config_writer.erl
+++ b/src/config_writer.erl
@@ -28,14 +28,17 @@
 %% @doc Saves a Section/Key/Value triple to the ini file File::filename()
 save_to_file({{Section, Key}, Value}, File) ->
     {ok, OldFileContents} = file:read_file(File),
-    Lines = re:split(OldFileContents, "\r\n|\n|\r|\032", [{return, list}]),
+    Lines = re:split(OldFileContents, "\r\n|\n|\r|\032", [{return, list}, unicode]),
 
     SectionLine = "[" ++ Section ++ "]",
-    {ok, Pattern} = re:compile(["^(", Key, "\\s*=)|\\[[a-zA-Z0-9\.\_-]*\\]"]),
+    {ok, Pattern} = re:compile(
+        ["^(", Key, "\\s*=)|\\[[a-zA-Z0-9\.\_-]*\\]"],
+        [unicode]
+    ),
 
     NewLines = process_file_lines(Lines, [], SectionLine, Pattern, Key, Value),
     NewFileContents = reverse_and_add_newline(strip_empty_lines(NewLines), []),
-    ok = file:write_file(File, NewFileContents).
+    ok = file:write_file(File, unicode:characters_to_binary(NewFileContents)).
 
 
 process_file_lines([Section|Rest], SeenLines, Section, Pattern, Key, Value) ->

http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/1e454a72/test/config_tests.erl
----------------------------------------------------------------------
diff --git a/test/config_tests.erl b/test/config_tests.erl
index 778e383..c6c5fec 100644
--- a/test/config_tests.erl
+++ b/test/config_tests.erl
@@ -98,7 +98,8 @@ config_test_() ->
             config_override_tests(),
             config_persistent_changes_tests(),
             config_no_files_tests(),
-            config_listener_behaviour_tests()
+            config_listener_behaviour_tests(),
+            config_unicode_tests()
         ]
     }.
 
@@ -218,6 +219,23 @@ config_listener_behaviour_tests() ->
         }
     }.
 
+config_unicode_tests() ->
+    {
+        "Config unicode tests",
+        {
+            foreachx,
+            fun setup/1, fun teardown/2,
+            [
+                {{temporary, [?CONFIG_DEFAULT, ?CONFIG_FIXTURE_2]},
+                 fun should_get_non_latin1_value/2},
+                {{persistent, [?CONFIG_DEFAULT, ?CONFIG_FIXTURE_2]},
+                 fun should_set_non_latin1_value/2},
+                {{persistent, [?CONFIG_DEFAULT, ?CONFIG_FIXTURE_2]},
+                 fun should_delete_non_latin1_value/2}
+            ]
+        }
+    }.
+
 should_load_all_configs() ->
     ?_assert(length(config:all()) > 0).
 
@@ -250,6 +268,12 @@ should_fail_to_get_non_string_value() ->
     ?_assertException(error, badarg,
                   config:get([f, o, o], [b, a, r], [b, a, z])).
 
+should_get_non_latin1_value(_, _) ->
+    ?_test(begin
+        ?assertEqual("true",
+            config:get("fizbang", [1090, 1077, 1089, 1090]))
+    end).
+
 should_return_any_supported_default() ->
     Values = [undefined, "list", true, false, 0.1, 1],
     Tests = [{lists:flatten(io_lib:format("for type(~p)", [V])), V}
@@ -278,6 +302,14 @@ should_fail_to_set_non_string_value() ->
     ?_assertException(error, badarg,
         config:set([f, o, o], [b, a, r], [b, a, z], false)).
 
+should_set_non_latin1_value(_, _) ->
+    ?_test(begin
+        ?assertEqual(ok,
+            config:set("fizbang", [1090, 1077, 1089, 1090], "false")),
+        ?assertEqual("false",
+            config:get("fizbang", [1090, 1077, 1089, 1090]))
+      end).
+
 should_return_undefined_atom_after_option_deletion() ->
     ?_assertEqual(undefined,
         begin
@@ -294,6 +326,12 @@ should_fail_to_delete_non_string_value() ->
     ?_assertException(error, badarg,
         config:delete([f, o, o], [b, a, r], false)).
 
+should_delete_non_latin1_value(_, _) ->
+    ?_test(begin
+        ?assertEqual(ok,
+            config:delete("fizbang", [1090, 1077, 1089, 1090]))
+    end).
+
 should_ensure_in_defaults(_, _) ->
     ?_test(begin
         ?assertEqual("500",

http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/1e454a72/test/fixtures/config_tests_2.ini
----------------------------------------------------------------------
diff --git a/test/fixtures/config_tests_2.ini b/test/fixtures/config_tests_2.ini
index 5f46357..86e61ce 100644
--- a/test/fixtures/config_tests_2.ini
+++ b/test/fixtures/config_tests_2.ini
@@ -20,3 +20,4 @@ port = 80
 
 [fizbang]
 unicode = normalized
+ั‚ะตัั‚ = true


Mime
View raw message