Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit469b28e

Browse files
committed
Core: Fix decoding non-JSON messages, negatively impacting templating
1 parent77d890d commit469b28e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

‎CHANGES.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ in progress
1313
- [Pushover]: Switch to using ``base64.b64decode()`` to support decoding
1414
a string. Thanks, @sumnerboy12.
1515
- [ntfy] Fix submitting newline characters in notification message text
16+
- Core: Fix decoding non-JSON messages, which negatively impacted outbound
17+
templating. Thanks, @Sc0th.
1618

1719

1820
2023-05-15 0.34.1

‎mqttwarn/core.py‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def get_key(item):
344344
q_in.put(job)
345345

346346

347-
defbuiltin_transform_data(topic:str,payload:t.AnyStr)->TdataType:
347+
defbuiltin_transform_data(topic:str,payload:t.Union[str,bytes])->TdataType:
348348
"""Return a dict with initial transformation data which is made
349349
available to all plugins"""
350350

@@ -397,11 +397,17 @@ def xform(function: str, orig_value: t.Any, transform_data: TdataType) -> t.Unio
397397
returnres
398398

399399

400-
defdecode_payload(section:str,topic:str,payload:t.AnyStr)->TdataType:
400+
defdecode_payload(section:str,topic:str,payload:t.Union[str,bytes])->TdataType:
401401
"""
402402
Decode message payload through transformation machinery.
403403
"""
404404

405+
ifisinstance(payload,bytes):
406+
try:
407+
payload=payload.decode("utf-8")
408+
exceptExceptionasex:
409+
logger.debug(f"Decoding from UTF-8 failed:{ex}. payload={truncate(payload)}")
410+
405411
transform_data=builtin_transform_data(topic,payload)
406412

407413
topic_data=context.get_topic_data(section,transform_data)
@@ -423,12 +429,9 @@ def decode_payload(section: str, topic: str, payload: t.AnyStr) -> TdataType:
423429
# the JSON keys into item to pass to the plugin, and create the outgoing
424430
# (i.e. transformed) message.
425431
try:
426-
ifisinstance(payload,bytes):
427-
outdata=payload.decode("utf-8")
428-
else:
429-
outdata=payload
430-
outdata=outdata.rstrip("\0")
431-
payload_data=json.loads(outdata)
432+
ifisinstance(payload,str):
433+
payload=payload.rstrip("\0")
434+
payload_data=json.loads(payload)
432435
transform_data.update(payload_data)
433436
exceptExceptionasex:
434437
logger.debug(f"Decoding JSON failed:{ex}. payload={truncate(payload)}")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp