Skip to content

Commit c75d440

Browse files
committed
Fix multiple commercial-at bug
1 parent d21aca7 commit c75d440

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/jid.erl

+18-8
Original file line numberDiff line numberDiff line change
@@ -379,41 +379,51 @@ binary_to_jid2(Jid, <<>>, N, S) ->
379379
{erlang:binary_part(Jid, {0, N}),
380380
erlang:binary_part(Jid, {N + 1, S}),
381381
<<>>};
382+
binary_to_jid2(_, <<$@, _J/binary>>, _N, _) ->
383+
error;
382384
binary_to_jid2(_, <<$/, _J/binary>>, _N, 0) ->
383385
error;
384386
binary_to_jid2(Jid, <<$/, _/binary>>, N, S) ->
385387
{erlang:binary_part(Jid, {0, N}),
386388
erlang:binary_part(Jid, {N + 1, S}),
387389
erlang:binary_part(Jid, {N + S + 2, byte_size(Jid) - N - S - 2})};
388-
binary_to_jid2(Jid, <<_, "/", _/binary>>, N, S) ->
390+
binary_to_jid2(Jid, <<A, "/", _/binary>>, N, S)
391+
when A =/= $@ ->
389392
{erlang:binary_part(Jid, {0, N}),
390393
erlang:binary_part(Jid, {N + 1, S + 1}),
391394
erlang:binary_part(Jid, {N + S + 3, byte_size(Jid) - N - S - 3})};
392-
binary_to_jid2(Jid, <<_, _, "/", _/binary>>, N, S) ->
395+
binary_to_jid2(Jid, <<A, B, "/", _/binary>>, N, S)
396+
when A =/= $@, B =/= $@ ->
393397
{erlang:binary_part(Jid, {0, N}),
394398
erlang:binary_part(Jid, {N + 1, S + 2}),
395399
erlang:binary_part(Jid, {N + S + 4, byte_size(Jid) - N - S - 4})};
396-
binary_to_jid2(Jid, <<_, _, _, "/", _/binary>>, N, S) ->
400+
binary_to_jid2(Jid, <<A, B, C, "/", _/binary>>, N, S)
401+
when A =/= $@, B =/= $@, C =/= $@ ->
397402
{erlang:binary_part(Jid, {0, N}),
398403
erlang:binary_part(Jid, {N + 1, S + 3}),
399404
erlang:binary_part(Jid, {N + S + 5, byte_size(Jid) - N - S - 5})};
400-
binary_to_jid2(Jid, <<_, _, _, _, "/", _/binary>>, N, S) ->
405+
binary_to_jid2(Jid, <<A, B, C, D, "/", _/binary>>, N, S)
406+
when A =/= $@, B =/= $@, C =/= $@, D =/= $@ ->
401407
{erlang:binary_part(Jid, {0, N}),
402408
erlang:binary_part(Jid, {N + 1, S + 4}),
403409
erlang:binary_part(Jid, {N + S + 6, byte_size(Jid) - N - S - 6})};
404-
binary_to_jid2(Jid, <<_, _, _, _, _, "/", _/binary>>, N, S) ->
410+
binary_to_jid2(Jid, <<A, B, C, D, E, "/", _/binary>>, N, S)
411+
when A =/= $@, B =/= $@, C =/= $@, D =/= $@, E =/= $@ ->
405412
{erlang:binary_part(Jid, {0, N}),
406413
erlang:binary_part(Jid, {N + 1, S + 5}),
407414
erlang:binary_part(Jid, {N + S + 7, byte_size(Jid) - N - S - 7})};
408-
binary_to_jid2(Jid, <<_, _, _, _, _, _, "/", _/binary>>, N, S) ->
415+
binary_to_jid2(Jid, <<A, B, C, D, E, F, "/", _/binary>>, N, S)
416+
when A =/= $@, B =/= $@, C =/= $@, D =/= $@, E =/= $@, F =/= $@ ->
409417
{erlang:binary_part(Jid, {0, N}),
410418
erlang:binary_part(Jid, {N + 1, S + 6}),
411419
erlang:binary_part(Jid, {N + S + 8, byte_size(Jid) - N - S - 8})};
412-
binary_to_jid2(Jid, <<_, _, _, _, _, _, _, "/", _/binary>>, N, S) ->
420+
binary_to_jid2(Jid, <<A, B, C, D, E, F, G, "/", _/binary>>, N, S)
421+
when A =/= $@, B =/= $@, C =/= $@, D =/= $@, E =/= $@, F =/= $@, G =/= $@ ->
413422
{erlang:binary_part(Jid, {0, N}),
414423
erlang:binary_part(Jid, {N + 1, S + 7}),
415424
erlang:binary_part(Jid, {N + S + 9, byte_size(Jid) - N - S - 9})};
416-
binary_to_jid2(Jid, <<_, _, _, _, _, _, _, _, J/binary>>, N, S) ->
425+
binary_to_jid2(Jid, <<A, B, C, D, E, F, G, H, J/binary>>, N, S)
426+
when A =/= $@, B =/= $@, C =/= $@, D =/= $@, E =/= $@, F =/= $@, G =/= $@, H =/= $@ ->
417427
binary_to_jid2(Jid, J, N, S + 8);
418428
binary_to_jid2(Jid, <<_C, J/binary>>, N, S) ->
419429
binary_to_jid2(Jid, J, N, S + 1).

test/jid_SUITE.erl

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ groups() ->
1616
{common, [parallel],
1717
[
1818
empty_server_fails,
19+
multiple_at_fails_as_invalid_jid,
1920
to_binary_with_binary_does_nothing,
2021
to_binary_can_convert_all_types_of_jids,
2122
binary_to_jid_succeeds_with_valid_binaries,
@@ -66,6 +67,9 @@ end_per_suite(C) ->
6667
empty_server_fails(_C) ->
6768
?assertEqual(error, jid:from_binary(<<"$@/">>)).
6869

70+
multiple_at_fails_as_invalid_jid(_C) ->
71+
?assertEqual(error, jid:from_binary(<<"jids@have@no@feelings">>)).
72+
6973
to_binary_with_binary_does_nothing(_C) ->
7074
Prop = ?FORALL(Bin, binary(),
7175
Bin =:= jid:to_binary(Bin)),

0 commit comments

Comments
 (0)