From a937bb173a0d9bb2244855e78cf7dd9cd8e78e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 27 Jun 2017 02:01:46 +0200 Subject: [PATCH] qubespolicy: allow spaces in action arguments This is natural to write space after coma. --- qubespolicy/__init__.py | 4 ++-- qubespolicy/tests/__init__.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qubespolicy/__init__.py b/qubespolicy/__init__.py index bcd7614e3..e55d88ee6 100755 --- a/qubespolicy/__init__.py +++ b/qubespolicy/__init__.py @@ -121,11 +121,11 @@ def __init__(self, line, filename=None, lineno=None): self.filename = filename try: - self.source, self.target, self.full_action = line.split() + self.source, self.target, self.full_action = line.split(maxsplit=2) except ValueError: raise PolicySyntaxError(filename, lineno, 'wrong number of fields') - (action, *params) = self.full_action.split(',') + (action, *params) = self.full_action.replace(' ', '').split(',') try: self.action = Action[action] except KeyError: diff --git a/qubespolicy/tests/__init__.py b/qubespolicy/tests/__init__.py index f82d149d6..079e1335c 100644 --- a/qubespolicy/tests/__init__.py +++ b/qubespolicy/tests/__init__.py @@ -155,15 +155,16 @@ def test_020_line_simple(self): self.assertIsNone(line.default_target) def test_021_line_simple(self): + # also check spaces in action field line = qubespolicy.PolicyRule( - '$tag:tag1 $type:AppVM ask,target=test-vm2,user=user', + '$tag:tag1 $type:AppVM ask, target=test-vm2, user=user', 'filename', 12) self.assertEqual(line.filename, 'filename') self.assertEqual(line.lineno, 12) self.assertEqual(line.action, qubespolicy.Action.ask) self.assertEqual(line.source, '$tag:tag1') self.assertEqual(line.target, '$type:AppVM') - self.assertEqual(line.full_action, 'ask,target=test-vm2,user=user') + self.assertEqual(line.full_action, 'ask, target=test-vm2, user=user') self.assertEqual(line.override_target, 'test-vm2') self.assertEqual(line.override_user, 'user') self.assertIsNone(line.default_target)