Undo parentheses escaping in ant_glob

This commit is contained in:
Thomas Nagy 2019-05-10 23:13:01 +02:00
parent 89146d9030
commit 8cbc8da5ce
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
3 changed files with 6 additions and 3 deletions

View File

@ -148,7 +148,7 @@ def test(ctx):
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)
tt("ant_glob (parentheses) ->", len(bld.srcnode.ant_glob('e.e+[(]e[)].txt', flat=False)), 1)
#print("ant_glob src ->", bld.srcnode.ant_glob('*.txt'))
def abspath(self):

View File

@ -73,7 +73,7 @@ def ant_matcher(s, ignorecase):
if k == '**':
accu.append(k)
else:
k = k.replace('.', '[.]').replace('*','.*').replace('?', '.').replace('+', '\\+').replace('(', '\\(').replace(')', '\\)')
k = k.replace('.', '[.]').replace('*', '.*').replace('?', '.').replace('+', '\\+')
k = '^%s$' % k
try:
exp = re.compile(k, flags=reflags)

View File

@ -63,6 +63,9 @@ def path_to_node(base_node, path, cached_nodes):
# normalize the path case to increase likelihood of a cache hit
path = os.path.normcase(path)
# ant_glob interprets [] and () characters, so those must be replaced
path = path.replace('[', '?').replace(']', '?').replace('(', '[(]').replace(')', '[)]')
node_lookup_key = (base_node, path)
try:
@ -73,7 +76,7 @@ def path_to_node(base_node, path, cached_nodes):
try:
node = cached_nodes[node_lookup_key]
except KeyError:
node_list = base_node.ant_glob([path], ignorecase=True, remove=False, quiet=True)
node_list = base_node.ant_glob([path], ignorecase=True, remove=False, quiet=True, regex=False)
node = cached_nodes[node_lookup_key] = node_list[0] if node_list else None
return node