From 249dc50218868977b8197f8384b04cf01a54733e Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Sun, 8 Sep 2019 22:55:22 +0200 Subject: [PATCH] Allow using /([^/]+/)? and (/[^/]+)?/ in patterns These are valid expressions in the middle of a pattern in a .fc file, in order to match an optional subdirectory level. Some recent commits introduced "/([^/]+/)?" in the policy: * commit b8f2c55109ba ("cups: use ([^/]+/)? to match a subdirectory of CUPS configuration") * commit 4b02c2230d02 ("authlogin: label utempter correctly on Debian") Signed-off-by: Nicolas Iooss --- testing/check_fc_files.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testing/check_fc_files.py b/testing/check_fc_files.py index c96991322..c7ed7e367 100755 --- a/testing/check_fc_files.py +++ b/testing/check_fc_files.py @@ -129,6 +129,10 @@ def analyze_fc_file(fc_path): print(f"{prefix}using (.*/)? without a previous slash could be a bug in {path} as it can match the empty string, please use /(.*/)? instead") # noqa retval = False + if re.search(r'[^/]\(\[\^/\]\+/\)\?', path): + print(f"{prefix}using ([^/]+/)? without a previous slash could be a bug in {path} as it can match the empty string, please use /([^/]+/)? instead") # noqa + retval = False + if re.search(r'[^/]\(\.\*/\)\*', path): print(f"{prefix}using (.*/)* without a previous slash could be a bug in {path} as it can match the empty string, please use /(.*/)* instead") # noqa retval = False @@ -202,6 +206,8 @@ def analyze_fc_file(fc_path): retval = False # Remove optional directories and filename parts + reduced_path = reduced_path.replace('/([^/]+/)?', '/') + reduced_path = reduced_path.replace('(/[^/]+)?/', '/') reduced_path = reduced_path.replace('[^/]*', '') reduced_path = reduced_path.replace('[^/]+', '∞') reduced_path = reduced_path.replace('[^/-]+', '∞')