From 82ef4d2b89099d5ea85eb7f9e18b30add03adaf0 Mon Sep 17 00:00:00 2001
From: Matthias Bodenbenner <m.bodenbenner@wzl-mq.rwth-aachen.de>
Date: Wed, 29 Mar 2023 09:58:37 +0200
Subject: [PATCH] 8.2.3

---
 PyPI-README.md       | 6 +++++-
 README.md            | 6 +++++-
 doc/source/usage.rst | 9 ++-------
 setup.py             | 2 +-
 src/mqtt/client.py   | 4 ++--
 5 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/PyPI-README.md b/PyPI-README.md
index fcb726a..ffe72ff 100644
--- a/PyPI-README.md
+++ b/PyPI-README.md
@@ -1,6 +1,6 @@
 # WZL-MQTT
 
-Current stable version: 2.5.1
+Current stable version: 2.5.2
 
 ## Documentation
 
@@ -78,6 +78,10 @@ while True:
 ```
 
 ## Changelog
+
+**2.5.2** - 2023-03-29
+  - client handles slash in at the end of prefix and the beginning of topic to avoid multiple consecutive slashes correctly now
+
 2.5.1
   - increased verbosity in case of errors by including the full stack trace
 
diff --git a/README.md b/README.md
index 8aeb1c5..75544da 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # WZL-MQTT
 
-Current stable version: 2.5.1
+Current stable version: 2.5.2
 
 ## Documentation
 
@@ -89,6 +89,10 @@ European Metrology Programme for Innovation and Research EMPIR). The EMPIR initi
 the European Union’s Horizon 2020 research and innovation programme and the EMPIR Participating States.
 
 ## Changelog
+
+**2.5.2** - 2023-03-29
+  - client handles slash in at the end of prefix and the beginning of topic to avoid multiple consecutive slashes correctly now
+
 2.5.1
   - increased verbosity in case of errors by including the full stack trace
 
diff --git a/doc/source/usage.rst b/doc/source/usage.rst
index c9ccf66..e278df5 100644
--- a/doc/source/usage.rst
+++ b/doc/source/usage.rst
@@ -30,20 +30,15 @@ Receiving MQTT Messages
 
     logger = mqtt.root_logger.get('Receiver')
 
+    # username and password required to connect to the broker
     MQTT_USER = ""
     MQTT_PASSWORD = ""
 
+    # address, port and virtual host of the broker to connect to
     MQTT_BROKER = "127.0.0.1"
     MQTT_PORT = 1883
     MQTT_VHOST = "/"
 
-    ## To connect to the central MQTT-Broker of MQ-MS use the settings below.
-    ## Ask Mark Sanders (sdr) or Matthias Bodenbenner (bdn) for personal credentials.
-    ## Set the "ssl" flag of the connect function to "True".
-    # MQTT_BROKER = "mqtt.wzl-mq.rwth-aachen.de"
-    # MQTT_PORT = 8883
-    # MQTT_VHOST = "metrology"
-
     topic = "#"  # set topic to subscribe according to MQTT syntax!
     qos = 0  # set QoS according to MQTT specifications!
 
diff --git a/setup.py b/setup.py
index 7fd16d1..7ce09fe 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@ with open("PyPI-README.md", "r", encoding="utf-8") as fh:
     long_description = fh.read()
 
 setup(name='wzl-mqtt',
-      version='2.5.1',
+      version='2.5.2',
       url='https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/',
       project_urls={
             "Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/-/issues",
diff --git a/src/mqtt/client.py b/src/mqtt/client.py
index 2df9462..a9730d8 100644
--- a/src/mqtt/client.py
+++ b/src/mqtt/client.py
@@ -210,7 +210,7 @@ class MQTTPublisher(MQTTClient):
         """
         try:
             if self.prefix is not None and self.prefix != "":
-                self._client.publish(self.prefix + "/" + topic.strip("/"),
+                self._client.publish(self.prefix.strip("/") + "/" + topic.strip("/"),
                                      message, qos, retain)
             else:
                 self._client.publish(topic.strip("/"), message, qos, retain)
@@ -272,7 +272,7 @@ class MQTTSubscriber(MQTTClient):
             SubscriptionError: If topic could not be subscribed successfully.
         """
         try:
-            topic = f'{self.prefix}/{topic}' if self.prefix is not None and self.prefix != "" else topic
+            topic = f'{self.prefix.strip("/")}/{topic.strip("/")}' if self.prefix is not None and self.prefix != "" else topic
             for s in self._subscriptions:
                 if s["topic"] == topic:
                     raise RuntimeError(
-- 
GitLab