Improve regular expressions
- Remove redundant escape - Remove erroneous character - Remove duplicate character
This commit is contained in:
@@ -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)))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user