Skip to content

Commit

Permalink
Handle bad globs passed to if --skip/-S
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Nov 16, 2021
1 parent 0ee6688 commit ecc95cb
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ecc95cb

Please sign in to comment.