aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/gcode.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2024-11-26 17:32:40 -0500
committerKevin O'Connor <kevin@koconnor.net>2024-12-01 14:16:13 -0500
commit49205f92ff7a2ee8d3ed5dc9992afb74d82c597f (patch)
tree97d19eb5fd240a107ebc2c9b01294db060ba348e /klippy/gcode.py
parent5493c603735d52ff1c03c0fa82a405edc30bd14c (diff)
downloadkutter-49205f92ff7a2ee8d3ed5dc9992afb74d82c597f.tar.gz
kutter-49205f92ff7a2ee8d3ed5dc9992afb74d82c597f.tar.xz
kutter-49205f92ff7a2ee8d3ed5dc9992afb74d82c597f.zip
gcode: Don't silently discard characters inside a command name
Don't silently drop leading numbers and unusual characters at the start of a command - for example, don't interpret '99M88' as 'M88'. Don't silently drop spaces in a command - for example, don't interpret "M 101" as the command "M101". Doing so will cause other parts of the code (such as get_raw_command_parameters() ) to not work properly. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/gcode.py')
-rw-r--r--klippy/gcode.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/klippy/gcode.py b/klippy/gcode.py
index ee2a09d9..8a6b3b8d 100644
--- a/klippy/gcode.py
+++ b/klippy/gcode.py
@@ -198,16 +198,14 @@ class GCodeDispatch:
line = line[:cpos]
# Break line into parts and determine command
parts = self.args_r.split(line.upper())
- numparts = len(parts)
- cmd = ""
- if numparts >= 3 and parts[1] != 'N':
- cmd = parts[1] + parts[2].strip()
- elif numparts >= 5 and parts[1] == 'N':
+ if ''.join(parts[:2]) == 'N':
# Skip line number at start of command
- cmd = parts[3] + parts[4].strip()
+ cmd = ''.join(parts[3:5]).strip()
+ else:
+ cmd = ''.join(parts[:3]).strip()
# Build gcode "params" dictionary
params = { parts[i]: parts[i+1].strip()
- for i in range(1, numparts, 2) }
+ for i in range(1, len(parts), 2) }
gcmd = GCodeCommand(self, cmd, origline, params, need_ack)
# Invoke handler for command
handler = self.gcode_handlers.get(cmd, self.cmd_default)