diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 0c6aac7c385..e2d0fe1c120 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -871,27 +871,56 @@ def main(*args): if os.path.isdir(filename): for root, dirs, files in os.walk(filename): - if glob_match.match(root): # skip (absolute) directories - del dirs[:] - continue - if is_hidden(root, options.check_hidden): # dir itself hidden + # skip (absolute) directories + try: + if glob_match.match(root): + del dirs[:] + continue + except re.error: + print("ERROR: --skip/-S has been fed an invalid glob", + file=sys.stderr) + return EX_USAGE + # ignore hidden directories + if is_hidden(root, options.check_hidden): continue for file_ in files: # ignore hidden files in directories if is_hidden(file_, options.check_hidden): continue - if glob_match.match(file_): # skip files - continue + # skip files + try: + if glob_match.match(file_): + continue + except re.error: + print("ERROR: --skip/-S has been fed an invalid glob", + file=sys.stderr) + return EX_USAGE fname = os.path.join(root, file_) - if glob_match.match(fname): # skip paths - continue + # skip paths + try: + if glob_match.match(fname): + continue + except re.error: + print("ERROR: --skip/-S has been fed an invalid glob", + file=sys.stderr) + return EX_USAGE + bad_count += parse_file( fname, colors, summary, misspellings, exclude_lines, file_opener, word_regex, ignore_word_regex, uri_regex, uri_ignore_words, context, options) # skip (relative) directories - dirs[:] = [dir_ for dir_ in dirs if not glob_match.match(dir_)] + try: + dirs[:] = [ + dir_ + for dir_ in dirs + if not glob_match.match(dir_) + ] + except re.error: + print("ERROR: --skip/-S has been fed an invalid glob", + file=sys.stderr) + return EX_USAGE elif not glob_match.match(filename): # skip files bad_count += parse_file(