diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index ed80726e..f9216116 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1846,7 +1846,7 @@ def strip_comment(line): for c in line: if c == ";" and not escaped: break - result += c if c != "\\" or escaped else "" + result += c escaped = (c == "\\") and not escaped return "".join(result) diff --git a/tests/util/test_comm_helpers.py b/tests/util/test_comm_helpers.py index 6f5c4a43..ff04ccb1 100644 --- a/tests/util/test_comm_helpers.py +++ b/tests/util/test_comm_helpers.py @@ -15,9 +15,9 @@ class TestCommHelpers(unittest.TestCase): @data( ("M117 Test", "M117 Test"), ("M117 Test ; foo", "M117 Test "), - ("M117 Test \\; foo", "M117 Test ; foo"), - ("M117 Test \\\\; foo", "M117 Test \\"), - ("M117 Test \\\\\\; foo", "M117 Test \\; foo"), + ("M117 Test \\; foo", "M117 Test \\; foo"), + ("M117 Test \\\\; foo", "M117 Test \\\\"), + ("M117 Test \\\\\\; foo", "M117 Test \\\\\\; foo"), ("; foo", "") ) @unpack