mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 16:35:02 +01:00
Merge 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. MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/545 Acked-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
commit
7fa74521fb
2 changed files with 16 additions and 17 deletions
|
@ -219,7 +219,7 @@ def strip_parenthesis(data):
|
|||
return data.strip()
|
||||
|
||||
def strip_quotes(data):
|
||||
if data[0] + data[-1] == '""':
|
||||
if len(data) > 1 and data[0] + data[-1] == '""':
|
||||
return data[1:-1]
|
||||
else:
|
||||
return data
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue