From 8dfcc5b5ec28263fc7a7555acb1c2900091161f3 Mon Sep 17 00:00:00 2001 From: JoeLametta Date: Wed, 16 Jan 2019 19:57:32 +0000 Subject: [PATCH] Improve regular expressions - Remove redundant escape - Remove erroneous character - Remove duplicate character --- whipper/common/common.py | 4 ++-- whipper/common/path.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/whipper/common/common.py b/whipper/common/common.py index 1b46d4e..675b021 100644 --- a/whipper/common/common.py +++ b/whipper/common/common.py @@ -285,9 +285,9 @@ def validate_template(template, kind): Raise exception if disc/track template includes invalid variables """ if kind == 'disc': - matches = re.findall(r'%[^A,R,S,X,d,r,x,y]', template) + matches = re.findall(r'%[^ARSXdrxy]', template) elif kind == 'track': - matches = re.findall(r'%[^A,R,S,X,a,d,n,r,s,t,x,y]', template) + matches = re.findall(r'%[^ARSXadnrstxy]', template) if '%' in template and matches: raise ValueError(kind + ' template string contains invalid ' 'variable(s): {}'.format(', '.join(matches))) diff --git a/whipper/common/path.py b/whipper/common/path.py index a5d0eb4..268b337 100644 --- a/whipper/common/path.py +++ b/whipper/common/path.py @@ -45,7 +45,7 @@ class PathFilter(object): def separators(path): # replace separators with a space-hyphen or hyphen path = re.sub(r'[:]', ' -', path, re.UNICODE) - path = re.sub(r'[\|]', '-', path, re.UNICODE) + path = re.sub(r'[|]', '-', path, re.UNICODE) return path # change all fancy single/double quotes to normal quotes @@ -56,12 +56,12 @@ class PathFilter(object): if self._special: path = separators(path) - path = re.sub(r'[\*\?&!\'\"\$\(\)`{}\[\]<>]', + path = re.sub(r'[*?&!\'\"$()`{}\[\]<>]', '_', path, re.UNICODE) if self._fat: path = separators(path) # : and | already gone, but leave them here for reference - path = re.sub(r'[:\*\?"<>|"]', '_', path, re.UNICODE) + path = re.sub(r'[:*?"<>|]', '_', path, re.UNICODE) return path