mirror of https://gitlab.com/ita1024/waf.git
Node: escape parentheses in ant_glob()
ant_matcher() converts an ANT glob pattern to an equivalent regex pattern. This commit adds support for escaping parenthesis in the input pattern so they don't end up being treated as a regex capture group. Also add a unit test to verify ant_glob()'s ability to handle special characters in the input pattern.
This commit is contained in:
parent
afa0dd15df
commit
e874342103
|
@ -143,9 +143,12 @@ def test(ctx):
|
|||
create('d.TXT')
|
||||
nd2 = bld.srcnode.make_node('d.TXT')
|
||||
nd2.write("test")
|
||||
nd3 = bld.srcnode.make_node('e.e+(e).txt')
|
||||
nd3.write("test")
|
||||
|
||||
tt("ant_glob ->", len(bld.srcnode.ant_glob('*.txt', flat=False)), 1)
|
||||
tt("ant_glob (icase) ->", len(bld.srcnode.ant_glob('*.txt', flat=False, ignorecase=True)), 2)
|
||||
tt("ant_glob ->", len(bld.srcnode.ant_glob('*.txt', flat=False)), 2)
|
||||
tt("ant_glob (icase) ->", len(bld.srcnode.ant_glob('*.txt', flat=False, ignorecase=True)), 3)
|
||||
tt("ant_glob (special) ->", len(bld.srcnode.ant_glob('e.e+(e).txt', flat=False)), 1)
|
||||
#print("ant_glob src ->", bld.srcnode.ant_glob('*.txt'))
|
||||
|
||||
def abspath(self):
|
||||
|
|
|
@ -73,7 +73,7 @@ def ant_matcher(s, ignorecase):
|
|||
if k == '**':
|
||||
accu.append(k)
|
||||
else:
|
||||
k = k.replace('.', '[.]').replace('*','.*').replace('?', '.').replace('+', '\\+')
|
||||
k = k.replace('.', '[.]').replace('*','.*').replace('?', '.').replace('+', '\\+').replace('(', '\\(').replace(')', '\\)')
|
||||
k = '^%s$' % k
|
||||
try:
|
||||
exp = re.compile(k, flags=reflags)
|
||||
|
|
Loading…
Reference in New Issue