From 555fc7f7643c407f23c19aee26460fb6ecfe8080 Mon Sep 17 00:00:00 2001 From: Niels Geens Date: Wed, 13 Nov 2024 11:52:04 +0100 Subject: [PATCH] Added check for superfluous arguments to response --- sia/response_parser.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sia/response_parser.py b/sia/response_parser.py index 040c433..000e5f3 100644 --- a/sia/response_parser.py +++ b/sia/response_parser.py @@ -107,8 +107,9 @@ class ResponseParser: target_id = root.get('id') if not target_id: return ParseErrorEntry(xml, "Delete command missing required 'id' attribute", entry_id, timestamp) + if len(root.attrib) > 1: + return ParseErrorEntry(xml, "Delete command should only have 'id' attribute", entry_id, timestamp) return DeleteCommand(target_id) - elif root.tag == 'stop': # Create stop command return StopCommand() @@ -117,34 +118,46 @@ class ResponseParser: # Create background script entry if not content: return ParseErrorEntry(xml, "Background entry missing script content", entry_id, timestamp) + if root.attrib: + return ParseErrorEntry(xml, "Background entry shouldn't have attributes", entry_id, timestamp) return BackgroundEntry(content, entry_id, timestamp) elif root.tag == 'repeat': # Create repeat script entry if not content: return ParseErrorEntry(xml, "Repeat entry missing script content", entry_id, timestamp) + if root.attrib: + return ParseErrorEntry(xml, "Repeat entry shouldn't have attributes", entry_id, timestamp) return RepeatEntry(content, entry_id, timestamp) elif root.tag == 'single': # Create single shot script entry if not content: - return ParseErrorEntry(xml, "Single shot entry missing script content", entry_id, timestamp) + return ParseErrorEntry(xml, "Single entry missing script content", entry_id, timestamp) + if root.attrib: + return ParseErrorEntry(xml, "Single entry shouldn't have attributes", entry_id, timestamp) return SingleEntry(content, entry_id, timestamp) elif root.tag == 'reasoning': # Create reasoning entry if not content: return ParseErrorEntry(xml, "Reasoning entry missing content", entry_id, timestamp) + if root.attrib: + return ParseErrorEntry(xml, "Reasoning entry shouldn't have attributes", entry_id, timestamp) return ReasoningEntry(content, entry_id, timestamp) elif root.tag == 'read_stdin': # Create read entry - no content required + if root.attrib: + return ParseErrorEntry(xml, "Read stdin entry shouldn't have attributes", entry_id, timestamp) return ReadEntry(self.io_buffer, entry_id, timestamp) elif root.tag == 'write_stdout': # Create write entry if not content: return ParseErrorEntry(xml, "Write entry missing content", entry_id, timestamp) + if root.attrib: + return ParseErrorEntry(xml, "Read stdin entry shouldn't have attributes", entry_id, timestamp) return WriteEntry(content, self.io_buffer, entry_id, timestamp) else: