From af94824bcad5bc242957f933b5aa6f410d8d3005 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 10 Mar 2021 11:01:07 +0800 Subject: [PATCH] fix #65 missing padding on seturl --- .vscode/launch.json | 2 +- meshtastic/__init__.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c53d43a..895b0ce 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -58,7 +58,7 @@ "request": "launch", "module": "meshtastic", "justMyCode": true, - "args": ["--seturl", "https://www.meshtastic.org/c/#GAMiENTxuzogKQdZ8Lz_q89Oab8qB0RlZmF1bHQ=" + "args": ["--seturl", "https://www.meshtastic.org/d/#CgIYAw" ] }, { diff --git a/meshtastic/__init__.py b/meshtastic/__init__.py index 851d561..ba966a7 100644 --- a/meshtastic/__init__.py +++ b/meshtastic/__init__.py @@ -391,7 +391,16 @@ class MeshInterface: # URLs are of the form https://www.meshtastic.org/d/#{base64_channel_set} # Split on '/#' to find the base64 encoded channel settings splitURL = url.split("/#") - decodedURL = base64.urlsafe_b64decode(splitURL[-1]) + b64 = splitURL[-1] + + # We normally strip padding to make for a shorter URL, but the python parser doesn't like + # that. So add back any missing padding + # per https://stackoverflow.com/a/9807138 + missing_padding = len(b64) % 4 + if missing_padding: + b64 += '='* (4 - missing_padding) + + decodedURL = base64.urlsafe_b64decode(b64) channelSet = apponly_pb2.ChannelSet() channelSet.ParseFromString(decodedURL)