Skip to content

Commit

Permalink
Merge branch 'release/2024.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Jun 2, 2024
2 parents f44d17f + 94c1641 commit 22d25f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

## develop

## 2024.2.1

- [ADD] `#kvc_list_string{}` のデフォルト値もチェックするようにする
- @voluntas

## 2024.2.0

- [ADD] `#kvc_list_string{}` に lowercase を追加する

- true にすると lowercase で返す
- @voluntas

Expand Down
2 changes: 1 addition & 1 deletion src/kvconf.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, kvconf,
[{description, "kvconf"},
{vsn, "2024.2.0"},
{vsn, "2024.2.1"},
{registered, []},
{applications, [kernel, stdlib]},
{env, []},
Expand Down
22 changes: 22 additions & 0 deletions src/kvconf_validate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ validate_string(_Value) ->
invalid_value.


%% is_list/1 チェックは default 用
validate_list_string(Value, _) when is_list(Value) ->
%% 全部バイナリかどうかを確認する
F = fun(V) when is_binary(V) ->
true;
(_) ->
false
end,
case lists:all(F, Value) of
true ->
{ok, Value};
false ->
invalid_value
end;
validate_list_string(Value, true) when is_binary(Value) ->
validate_list_string(list_to_binary(string:to_lower(binary_to_list(Value))), false);
validate_list_string(Value, false) when is_binary(Value) ->
Expand Down Expand Up @@ -628,6 +642,10 @@ validate_one_test() ->


validate_list_string_test() ->
%% デフォルト
?assertEqual({ok, [~"x-abc-efg", ~"x-y-z"]},
validate_list_string([~"x-abc-efg", ~"x-y-z"], true)),

?assertEqual({ok, [~"x-abc-efg", ~"x-y-z"]},
validate_list_string(~"X-ABC-EFG, X-Y-Z", true)),

Expand All @@ -642,6 +660,10 @@ validate_list_string_test() ->
?assertEqual({ok, [~"a", ~"b"]},
validate_list_string(~" a, , , b ", false)),

%% デフォルト
?assertEqual(invalid_value,
validate_list_string([~"x-abc-efg", 1], true)),

?assertEqual(invalid_value,
validate_list_string(1, false)),

Expand Down

0 comments on commit 22d25f0

Please sign in to comment.