Skip to content

Commit 400f295

Browse files
authored
Merge pull request #258 from FoamyGuy/msg_size_limit
Enforce size limit in publish()
2 parents 7ec01da + 1db831f commit 400f295

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎adafruit_minimqtt/adafruit_minimqtt.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def ping(self) -> list[int]:
669669
)
670670
return rcs
671671

672-
def publish( # noqa: PLR0912, Too many branches
672+
def publish( # noqa: PLR0912, PLR0915, Too many branches, Too many statements
673673
self,
674674
topic: str,
675675
msg: Union[str, int, float, bytes],
@@ -700,7 +700,11 @@ def publish( # noqa: PLR0912, Too many branches
700700
else:
701701
raise ValueError("Invalid message data type.")
702702
if len(msg) > MQTT_MSG_MAX_SZ:
703-
raise ValueError(f"Message size larger than {MQTT_MSG_MAX_SZ} bytes.")
703+
raise ValueError(f"Message size larger than protocol max {MQTT_MSG_MAX_SZ} bytes.")
704+
if len(msg) > self._msg_size_lim:
705+
raise ValueError(
706+
f"Message size larger than configured limit {self._msg_size_lim} bytes."
707+
)
704708

705709
self._valid_qos(qos)
706710

0 commit comments

Comments
 (0)