Skip to content

Commit

Permalink
mod_base: let the unique name validation first use 'z_string:to_name/1'.
Browse files Browse the repository at this point in the history
Consider '_' as an invalid unique name. Issue #1579

(cherry picked from commit 7999c00)
  • Loading branch information
mworrell committed Jan 24, 2017
1 parent 51337dd commit 2b95423
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions modules/mod_base/validators/validator_base_name_unique.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ render_validator(name_unique, TriggerId, TargetId, Args, Context) ->
-spec validate(name_unique, string(), term(), list(), #context{}) ->
{{ok, []}, #context{}} | {{error, m_rsc:resource(), atom() | string()}, #context{}}.
validate(name_unique, Id, Value, Args, Context) ->
Name = z_string:to_lower(z_string:trim(Value)),
RscId = proplists:get_value(id, Args),
case m_rsc:name_lookup(Name, Context) of
undefined ->
{{ok, []}, Context};
RscId ->
{{ok, []}, Context};
_ ->
Message = proplists:get_value(failure_message, Args, invalid),
{{error, Id, Message}, Context}
Message = proplists:get_value(failure_message, Args, invalid),
case z_string:to_name(Value) of
<<>> ->
{{error, Id, Message}, Context};
<<"_">> ->
{{error, Id, Message}, Context};
Name ->
RscId = proplists:get_value(id, Args),
case m_rsc:name_lookup(Name, Context) of
undefined ->
{{ok, ""}, Context};
RscId ->
{{ok, ""}, Context};
_ ->
Message = proplists:get_value(failure_message, Args, invalid),
{{error, Id, Message}, Context}
end
end.

%% @doc Handle the validation during form entry.
Expand Down

0 comments on commit 2b95423

Please sign in to comment.