2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 14:25:52 +00:00

Fix strip_quotes() to handle empty strings

strip_quotes() assumed its parameter is at least one character long, and
errored out on an empty string.

It also converted a string consisting of a single quote to an empty
string because that single quote had a quote as first and last char.

This commit fixes these two bugs.

Also rewrite TestStripQuotes to use tests[], and add some test for an empty
string, a one-char path (just a slash) and a single quote.
This commit is contained in:
Christian Boltz
2020-05-24 13:33:12 +02:00
parent f891dad070
commit 373e8e23b1
2 changed files with 16 additions and 17 deletions

View File

@@ -628,23 +628,22 @@ class TestStripParenthesis(AATest):
self.assertEqual(strip_parenthesis(params), expected)
class TestStripQuotes(AATest):
def test_strip_quotes_01(self):
self.assertEqual('foo', strip_quotes('foo'))
def test_strip_quotes_02(self):
self.assertEqual('foo', strip_quotes('"foo"'))
def test_strip_quotes_03(self):
self.assertEqual('"foo', strip_quotes('"foo'))
def test_strip_quotes_04(self):
self.assertEqual('foo"', strip_quotes('foo"'))
def test_strip_quotes_05(self):
self.assertEqual('', strip_quotes('""'))
def test_strip_quotes_06(self):
self.assertEqual('foo"bar', strip_quotes('foo"bar'))
def test_strip_quotes_07(self):
self.assertEqual('foo"bar', strip_quotes('"foo"bar"'))
def test_strip_quotes_08(self):
self.assertEqual('"""foo"bar"""', strip_quotes('""""foo"bar""""'))
tests = [
('foo', 'foo'),
('"foo"', 'foo'),
('"foo', '"foo'),
('foo"', 'foo"'),
('""', ''),
('foo"bar', 'foo"bar'),
('"foo"bar"', 'foo"bar'),
('""""foo"bar""""', '"""foo"bar"""'),
('', ''),
('/', '/'),
('"', '"'),
]
def _run_test(self, params, expected):
self.assertEqual(strip_quotes(params), expected)
setup_aa(aa)