From d02976156e664e99e991797d9e4ae31829d5a2e7 Mon Sep 17 00:00:00 2001 From: Roger Light Date: Fri, 20 Jan 2023 22:46:32 +0000 Subject: [PATCH] Raise error on `subscribe()` when `topic` is an empty list. Closes #690. Thanks to peromvikgoodtech. --- ChangeLog.txt | 1 + examples/client_sub.py | 2 +- src/paho/mqtt/client.py | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 975955f..ef16bc6 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,7 @@ v1.6.2 - 2021-xx-xx - Fix handling of MQTT v5.0 PUBREL messages with remaining length not equal to 2. Closes #696. +- Raise error on `subscribe()` when `topic` is an empty list. Closes #690. v1.6.1 - 2021-10-21 diff --git a/examples/client_sub.py b/examples/client_sub.py index 9cd54e2..e03bb44 100755 --- a/examples/client_sub.py +++ b/examples/client_sub.py @@ -54,6 +54,6 @@ mqttc.on_subscribe = on_subscribe # Uncomment to enable debug messages # mqttc.on_log = on_log mqttc.connect("mqtt.eclipseprojects.io", 1883, 60) -mqttc.subscribe("$SYS/#", 0) +mqttc.subscribe([]) mqttc.loop_forever() diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index 66129e5..1020eea 100644 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -1467,6 +1467,8 @@ class Client(object): raise ValueError('Invalid topic.') topic_qos_list = [(topic.encode('utf-8'), qos)] elif isinstance(topic, list): + if len(topic) == 0: + raise ValueError('Empty topic list') topic_qos_list = [] if self._protocol == MQTTv5: for t, o in topic: -- GitLab