##// END OF EJS Templates
Unescape failed glob patterns in shellglob
Takafumi Arakaki -
Show More
@@ -356,6 +356,13 b' def expand_path(s):'
356 356 return s
357 357
358 358
359 def unescape_glob(string):
360 """Unescape glob pattern in `string`."""
361 for pattern in '*[]!?':
362 string = string.replace(r'\{0}'.format(pattern), pattern)
363 return string
364
365
359 366 def shellglob(args):
360 367 """
361 368 Do glob expansion for each element in `args` and return a flattened list.
@@ -365,7 +372,7 b' def shellglob(args):'
365 372 """
366 373 expanded = []
367 374 for a in args:
368 expanded.extend(glob.glob(a) or [a])
375 expanded.extend(glob.glob(a) or [unescape_glob(a)])
369 376 return expanded
370 377
371 378
@@ -475,5 +475,14 b' def test_shellglob():'
475 475 + filenames_start_with_a
476 476 + filenames_end_with_b
477 477 + ['*c'])
478
479 assert_match([r'\*'], ['*'])
480 assert_match([r'a\*', 'a*'], ['a*'] + filenames_start_with_a)
481 assert_match(['a[012]'], filenames_start_with_a)
482 assert_match([r'a\[012]'], ['a[012]'])
478 483 finally:
479 484 os.chdir(save)
485
486
487 def test_unescape_glob():
488 nt.assert_equals(path.unescape_glob(r'\*\[\!\]\?'), '*[!]?')
General Comments 0
You need to be logged in to leave comments. Login now