Skip to content

Commit

Permalink
MB-44513: Trim paths before setting them
Browse files Browse the repository at this point in the history
The paths are trimmed anyway in couchdb. If the same API called
one more time and we don't trim them, we will not be able to
figure out that the path has not changed.

Basically if path contains spaces the logic that compares old and
new paths breaks.

Change-Id: Ie5f803dc80cba64c1c53c97f73299bfb7f2d4961
Reviewed-on: http://review.couchbase.org/c/ns_server/+/164681
Well-Formed: Build Bot <build@couchbase.com>
Tested-by: Timofey Barmin <timofey.barmin@couchbase.com>
Reviewed-by: Artem Stemkovski <artem@couchbase.com>
  • Loading branch information
timofey-barmin committed Nov 5, 2021
1 parent 9d2bd59 commit edb6b86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/menelaus_web_node.erl
Expand Up @@ -82,11 +82,11 @@ handle_node_init(Req) ->
[validator:has_params(_), validator:unsupported(_)]).

node_init_validators() ->
[validator:touch(dataPath, _),
validator:touch(indexPath, _),
validator:touch(analyticsPath, _),
validator:touch(eventingPath, _),
validator:touch(javaHome, _),
[validator:trimmed_string(dataPath, _),
validator:trimmed_string(indexPath, _),
validator:trimmed_string(analyticsPath, _),
validator:trimmed_string(eventingPath, _),
validator:trimmed_string(javaHome, _),
validator:validate(
fun (_) ->
case ns_cluster_membership:system_joinable() of
Expand Down
13 changes: 12 additions & 1 deletion src/validator.erl
Expand Up @@ -28,6 +28,7 @@
convert/3,
one_of/3,
string/2,
trimmed_string/2,
boolean/2,
integer/2,
integer/4,
Expand Down Expand Up @@ -346,15 +347,25 @@ one_of(Name, List, State) ->
end
end, Name, State).

trimmed_string(Name, State) ->
string(Name, true, State).

string(Name, State) ->
string(Name, false, State).

string(Name, Trim, State) ->
validate(
case is_json(State) of
true ->
fun (Binary) when is_binary(Binary) ->
fun (Binary) when is_binary(Binary), Trim ->
{value, string:trim(binary_to_list(Binary))};
(Binary) when is_binary(Binary) ->
{value, binary_to_list(Binary)};
(_) ->
{error, "Value must be json string"}
end;
false when Trim ->
fun (S) -> {value, string:trim(S)} end;
false ->
fun (_) -> ok end
end, Name, State).
Expand Down

0 comments on commit edb6b86

Please sign in to comment.