Added check for superfluous arguments to response

This commit is contained in:
Niels Geens
2024-11-13 11:52:04 +01:00
parent aa37182614
commit 555fc7f764

View File

@@ -107,8 +107,9 @@ class ResponseParser:
target_id = root.get('id') target_id = root.get('id')
if not target_id: if not target_id:
return ParseErrorEntry(xml, "Delete command missing required 'id' attribute", entry_id, timestamp) 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) return DeleteCommand(target_id)
elif root.tag == 'stop': elif root.tag == 'stop':
# Create stop command # Create stop command
return StopCommand() return StopCommand()
@@ -117,34 +118,46 @@ class ResponseParser:
# Create background script entry # Create background script entry
if not content: if not content:
return ParseErrorEntry(xml, "Background entry missing script content", entry_id, timestamp) 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) return BackgroundEntry(content, entry_id, timestamp)
elif root.tag == 'repeat': elif root.tag == 'repeat':
# Create repeat script entry # Create repeat script entry
if not content: if not content:
return ParseErrorEntry(xml, "Repeat entry missing script content", entry_id, timestamp) 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) return RepeatEntry(content, entry_id, timestamp)
elif root.tag == 'single': elif root.tag == 'single':
# Create single shot script entry # Create single shot script entry
if not content: 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) return SingleEntry(content, entry_id, timestamp)
elif root.tag == 'reasoning': elif root.tag == 'reasoning':
# Create reasoning entry # Create reasoning entry
if not content: if not content:
return ParseErrorEntry(xml, "Reasoning entry missing content", entry_id, timestamp) 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) return ReasoningEntry(content, entry_id, timestamp)
elif root.tag == 'read_stdin': elif root.tag == 'read_stdin':
# Create read entry - no content required # 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) return ReadEntry(self.io_buffer, entry_id, timestamp)
elif root.tag == 'write_stdout': elif root.tag == 'write_stdout':
# Create write entry # Create write entry
if not content: if not content:
return ParseErrorEntry(xml, "Write entry missing content", entry_id, timestamp) 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) return WriteEntry(content, self.io_buffer, entry_id, timestamp)
else: else: