Skip to content

Commit

Permalink
Validate domainpart against RFC
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Waz committed Nov 21, 2022
1 parent a70d876 commit a3ff4e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/jid.erl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ nodeprep(_) ->

%% @doc Prepares the server part of a jid
-spec nameprep(server()) -> lserver() | error.
nameprep(<<>>) ->
error;
nameprep(S) when is_binary(S), byte_size(S) < ?SANE_LIMIT ->
R = stringprep:nameprep(S),
validate_binary_size(R);
Expand Down
17 changes: 16 additions & 1 deletion test/jid_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ groups() ->
to_bare_binary_equals_to_bare_then_to_binary,
to_lower_to_bare_equals_to_bare_to_lower,
make_to_lus_equals_to_lower_to_lus,
make_bare_like_make_with_empty_resource
make_bare_like_make_with_empty_resource,
make_empty_domain,
make_bare_empty_domain,
make_noprep_empty_domain
]},
{old_comparison, [parallel], [
with_nif_from_binary,
Expand Down Expand Up @@ -263,6 +266,18 @@ make_bare_like_make_with_empty_resource(_) ->
jid:make(U, S, <<>>))),
run_property(Prop, 200, 1, 100).

make_empty_domain(_) ->
?assertEqual(error, jid:make(jid_gen:username(), <<"">>, jid_gen:resource())),
?assertEqual(error, jid:make({jid_gen:username(), <<"">>, jid_gen:resource()})).

make_bare_empty_domain(_) ->
?assertEqual(error, jid:make_bare(jid_gen:username(), <<"">>)).

make_noprep_empty_domain(_) ->
Prop = ?FORALL({U, S, R},
{jid_gen:username(), <<"">>, jid_gen:resource()},
jid:make_noprep(U,S,R) == jid:make_noprep({U,S,R})),
run_property(Prop, 10, 1, 500).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Original code kept for documentation purposes
Expand Down

0 comments on commit a3ff4e0

Please sign in to comment.