Skip to content

Commit ecc95cb

Browse files
Handle bad globs passed to if --skip/-S
1 parent 0ee6688 commit ecc95cb

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

codespell_lib/_codespell.py

+38-9
Original file line numberDiff line numberDiff line change
@@ -871,27 +871,56 @@ def main(*args):
871871

872872
if os.path.isdir(filename):
873873
for root, dirs, files in os.walk(filename):
874-
if glob_match.match(root): # skip (absolute) directories
875-
del dirs[:]
876-
continue
877-
if is_hidden(root, options.check_hidden): # dir itself hidden
874+
# skip (absolute) directories
875+
try:
876+
if glob_match.match(root):
877+
del dirs[:]
878+
continue
879+
except re.error:
880+
print("ERROR: --skip/-S has been fed an invalid glob",
881+
file=sys.stderr)
882+
return EX_USAGE
883+
# ignore hidden directories
884+
if is_hidden(root, options.check_hidden):
878885
continue
879886
for file_ in files:
880887
# ignore hidden files in directories
881888
if is_hidden(file_, options.check_hidden):
882889
continue
883-
if glob_match.match(file_): # skip files
884-
continue
890+
# skip files
891+
try:
892+
if glob_match.match(file_):
893+
continue
894+
except re.error:
895+
print("ERROR: --skip/-S has been fed an invalid glob",
896+
file=sys.stderr)
897+
return EX_USAGE
885898
fname = os.path.join(root, file_)
886-
if glob_match.match(fname): # skip paths
887-
continue
899+
# skip paths
900+
try:
901+
if glob_match.match(fname):
902+
continue
903+
except re.error:
904+
print("ERROR: --skip/-S has been fed an invalid glob",
905+
file=sys.stderr)
906+
return EX_USAGE
907+
888908
bad_count += parse_file(
889909
fname, colors, summary, misspellings, exclude_lines,
890910
file_opener, word_regex, ignore_word_regex, uri_regex,
891911
uri_ignore_words, context, options)
892912

893913
# skip (relative) directories
894-
dirs[:] = [dir_ for dir_ in dirs if not glob_match.match(dir_)]
914+
try:
915+
dirs[:] = [
916+
dir_
917+
for dir_ in dirs
918+
if not glob_match.match(dir_)
919+
]
920+
except re.error:
921+
print("ERROR: --skip/-S has been fed an invalid glob",
922+
file=sys.stderr)
923+
return EX_USAGE
895924

896925
elif not glob_match.match(filename): # skip files
897926
bad_count += parse_file(

0 commit comments

Comments
 (0)