Skip to content

Commit

Permalink
Change client id validation range in codec-mqtt
Browse files Browse the repository at this point in the history
Motivation:

In MQTT 3.1 specification, "The Client Identifier (Client ID) is between
1 and 23 characters long, and uniquely identifies the client to the
server". But, current client id validation length is 0~23. It must be
1~23. The empty string is invalid client id in MQTT 3.1

Modifications:

Change isValidClientId method. Add MIN_CLIENT_ID_LENGTH.

Result:

The validation check for client id length is between 1 and 23.
  • Loading branch information
jongyeol authored and normanmaurer committed Oct 13, 2014
1 parent 547a0b0 commit 9589e0b
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
final class MqttCodecUtil {

private static final char[] TOPIC_WILDCARDS = {'#', '+'};
private static final int MIN_CLIENT_ID_LENGTH = 1;
private static final int MAX_CLIENT_ID_LENGTH = 23;

static boolean isValidPublishTopicName(String topicName) {
Expand All @@ -38,7 +39,8 @@ static boolean isValidMessageId(int messageId) {
}

static boolean isValidClientId(String clientId) {
return clientId != null && clientId.length() <= MAX_CLIENT_ID_LENGTH;
return clientId != null && clientId.length() >= MIN_CLIENT_ID_LENGTH &&
clientId.length() <= MAX_CLIENT_ID_LENGTH;
}

static MqttFixedHeader validateFixedHeader(MqttFixedHeader mqttFixedHeader) {
Expand Down

0 comments on commit 9589e0b

Please sign in to comment.