fix(frame): remove empty topic check, because it checked in emqx_channel
This commit is contained in:
parent
93411ecd4b
commit
8a269099ad
|
@ -273,7 +273,6 @@ parse_packet(#mqtt_packet_header{type = ?PUBLISH, qos = QoS}, Bin,
|
|||
(PacketId =/= undefined) andalso
|
||||
StrictMode andalso validate_packet_id(PacketId),
|
||||
{Properties, Payload} = parse_properties(Rest1, Ver, StrictMode),
|
||||
ok = ensure_topic_name_valid(StrictMode, TopicName, Properties),
|
||||
Publish = #mqtt_packet_publish{topic_name = TopicName,
|
||||
packet_id = PacketId,
|
||||
properties = Properties
|
||||
|
@ -360,7 +359,6 @@ parse_will_message(Packet = #mqtt_packet_connect{will_flag = true,
|
|||
{Props, Rest} = parse_properties(Bin, Ver, StrictMode),
|
||||
{Topic, Rest1} = parse_utf8_string(Rest, StrictMode),
|
||||
{Payload, Rest2} = parse_binary_data(Rest1),
|
||||
ok = ensure_topic_name_valid(StrictMode, Topic, Props),
|
||||
{Packet#mqtt_packet_connect{will_props = Props,
|
||||
will_topic = Topic,
|
||||
will_payload = Payload
|
||||
|
@ -526,15 +524,6 @@ parse_binary_data(Bin)
|
|||
when 2 > byte_size(Bin) ->
|
||||
error(malformed_binary_data_length).
|
||||
|
||||
ensure_topic_name_valid(false, _TopicName, _Properties) ->
|
||||
ok;
|
||||
ensure_topic_name_valid(true, TopicName, _Properties) when TopicName =/= <<>> ->
|
||||
ok;
|
||||
ensure_topic_name_valid(true, <<>>, #{'Topic-Alias' := _}) ->
|
||||
ok;
|
||||
ensure_topic_name_valid(true, <<>>, _) ->
|
||||
error(empty_topic_name).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Serialize MQTT Packet
|
||||
%%--------------------------------------------------------------------
|
||||
|
|
|
@ -46,8 +46,6 @@ groups() ->
|
|||
t_parse_frame_malformed_variable_byte_integer,
|
||||
t_parse_frame_variable_byte_integer,
|
||||
t_parse_malformed_utf8_string,
|
||||
t_parse_empty_topic_name,
|
||||
t_parse_empty_topic_name_with_alias,
|
||||
t_parse_frame_proxy_protocol %% proxy_protocol_config_disabled packet.
|
||||
]},
|
||||
{connect, [parallel],
|
||||
|
@ -164,21 +162,6 @@ t_parse_malformed_utf8_string(_) ->
|
|||
ParseState = emqx_frame:initial_parse_state(#{strict_mode => true}),
|
||||
?catch_error(utf8_string_invalid, emqx_frame:parse(MalformedPacket, ParseState)).
|
||||
|
||||
t_parse_empty_topic_name(_) ->
|
||||
Packet = ?PUBLISH_PACKET(?QOS_1, <<>>, 1, #{}, <<>>),
|
||||
?assertEqual(Packet, parse_serialize(Packet, #{strict_mode => false})),
|
||||
?catch_error(empty_topic_name, parse_serialize(Packet, #{strict_mode => true})).
|
||||
|
||||
t_parse_empty_topic_name_with_alias(_) ->
|
||||
Props = #{'Topic-Alias' => 16#AB},
|
||||
Packet = ?PUBLISH_PACKET(?QOS_1, <<>>, 1, Props, <<>>),
|
||||
?assertEqual(
|
||||
Packet, parse_serialize(Packet, #{strict_mode => false, version => ?MQTT_PROTO_V5})
|
||||
),
|
||||
?assertEqual(
|
||||
Packet, parse_serialize(Packet, #{strict_mode => true, version => ?MQTT_PROTO_V5})
|
||||
).
|
||||
|
||||
t_parse_frame_proxy_protocol(_) ->
|
||||
BinList = [ <<"PROXY TCP4 ">>, <<"PROXY TCP6 ">>, <<"PROXY UNKNOWN">>
|
||||
, <<"\r\n\r\n\0\r\nQUIT\n">>],
|
||||
|
|
Loading…
Reference in New Issue