mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-09-01 06:45:38 +00:00
Use string startswith() and endswith() methods
... instead of slicing to check for prefixes and suffixes.
This change prevents a crash in aa-mergeprof - if `replacement` is empty,
trying to access `replacement[0]` causes an IndexError.
Using `.startswith()` works without crashing.
This backports parts of the severity.py changes in
commit 091c6ad59d
by Mark Grassi.
This commit is contained in:
@@ -168,9 +168,9 @@ class Severity(object):
|
||||
leading = True
|
||||
if resource.find(variable + "/") != -1 and resource.find(variable + "//") == -1:
|
||||
trailing = True
|
||||
if replacement[0] == '/' and replacement[:2] != '//' and leading: # finds if the replacement has leading / or not
|
||||
if replacement.startswith('/') and not replacement.startswith('//') and leading: # finds if the replacement has leading / or not
|
||||
replacement = replacement[1:]
|
||||
if replacement[-1] == '/' and replacement[-2:] != '//' and trailing:
|
||||
if replacement.endswith('/') and not replacement.endswith('//') and trailing:
|
||||
replacement = replacement[:-1]
|
||||
return resource.replace(variable, replacement)
|
||||
|
||||
|
Reference in New Issue
Block a user