From d498347a01266fc77ad9086611495802096d00f6 Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Tue, 27 Feb 2018 11:12:18 -0800 Subject: [PATCH] rule-syntax-check: add support for escaped double quotes Add support to backslash-escaped double quote inside a string. Tested by modifying src/login/70-uaccess.rules to include: ACTION=="remove" it", GOTO="uaccess_end" And had the rule checker complain about it: $ test/rule-syntax-check.py src/login/70-uaccess.rules # looking at src/login/70-uaccess.rules Invalid line src/login/70-uaccess.rules:10: ACTION=="remove" it", GOTO="uaccess_end" clause: ACTION=="remove" it" --- test/rule-syntax-check.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/rule-syntax-check.py b/test/rule-syntax-check.py index dcbab5fc6d..1a58d17328 100755 --- a/test/rule-syntax-check.py +++ b/test/rule-syntax-check.py @@ -28,10 +28,11 @@ rules_files = sys.argv[1:] if not rules_files: sys.exit('Specify files to test as arguments') -no_args_tests = re.compile(r'(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|PROGRAM|RESULT|TEST)\s*(?:=|!)=\s*"(.*)"$') -args_tests = re.compile(r'(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*"(.*)"$') -no_args_assign = re.compile(r'(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|RUN|LABEL|GOTO|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*"(.*)"$') -args_assign = re.compile(r'(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*"(.*)"$') +quoted_string_re = r'"(?:[^\\"]|\\.)*"' +no_args_tests = re.compile(r'(ACTION|DEVPATH|KERNELS?|NAME|SYMLINK|SUBSYSTEMS?|DRIVERS?|TAG|PROGRAM|RESULT|TEST)\s*(?:=|!)=\s*' + quoted_string_re + '$') +args_tests = re.compile(r'(ATTRS?|ENV|TEST){([a-zA-Z0-9/_.*%-]+)}\s*(?:=|!)=\s*' + quoted_string_re + '$') +no_args_assign = re.compile(r'(NAME|SYMLINK|OWNER|GROUP|MODE|TAG|RUN|LABEL|GOTO|OPTIONS|IMPORT)\s*(?:\+=|:=|=)\s*' + quoted_string_re + '$') +args_assign = re.compile(r'(ATTR|ENV|IMPORT|RUN){([a-zA-Z0-9/_.*%-]+)}\s*(=|\+=)\s*' + quoted_string_re + '$') result = 0 buffer = ''