From 7b5d2e3e0c3c09e0f0d419bb428e8c01baa3f820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 18 Oct 2018 17:32:32 +0200 Subject: [PATCH] Allow whitespace after : in M114 responses Closes #2839 --- src/octoprint/util/comm.py | 4 ++-- tests/util/test_comm_helpers.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index bee3e0837..68ffbf039 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -126,7 +126,7 @@ Groups will be as follows: * ``target``: new target temperature (float) """ -regex_position = re.compile("X:(?P{float})\s*Y:(?P{float})\s*Z:(?P{float})\s*((E:(?P{float}))|(?P(E\d+:{float}\s*)+))".format(float=regex_float_pattern)) +regex_position = re.compile("X:\s*(?P{float})\s*Y:\s*(?P{float})\s*Z:\s*(?P{float})\s*((E:\s*(?P{float}))|(?P(E\d+:\s*{float}\s*)+))".format(float=regex_float_pattern)) """Regex for matching position reporting. Groups will be as follows: @@ -138,7 +138,7 @@ Groups will be as follows: * ``es``: multiple E coordinates if present, to be parsed further with regex_e_positions """ -regex_e_positions = re.compile("E(?P\d+):(?P{float})".format(float=regex_float_pattern)) +regex_e_positions = re.compile("E(?P\d+):\s*(?P{float})".format(float=regex_float_pattern)) """Regex for matching multiple E coordinates in a position report. Groups will be as follows: diff --git a/tests/util/test_comm_helpers.py b/tests/util/test_comm_helpers.py index 119ff406d..1524dbd99 100644 --- a/tests/util/test_comm_helpers.py +++ b/tests/util/test_comm_helpers.py @@ -333,6 +333,12 @@ class TestCommHelpers(unittest.TestCase): e4=0.0, e5=0.0)), + # whitespace after the :, e.g. AlfaWise U20, see #2839 + ("X:150.0 Y:150.0 Z: 0.7 E: 0.0", dict(x=150.0, + y=150.0, + z=0.7, + e=0.0)), + # invalid ("", None), ("X:62.417 Y:64.781 Z:0.2", None)