@@ -872,27 +872,56 @@ def main(*args):
872872
873873 if os .path .isdir (filename ):
874874 for root , dirs , files in os .walk (filename ):
875- if glob_match .match (root ): # skip (absolute) directories
876- del dirs [:]
877- continue
878- if is_hidden (root , options .check_hidden ): # dir itself hidden
875+ # skip (absolute) directories
876+ try :
877+ if glob_match .match (root ):
878+ del dirs [:]
879+ continue
880+ except re .error :
881+ print ("ERROR: --skip/-S has been fed an invalid glob" ,
882+ file = sys .stderr )
883+ return EX_USAGE
884+ # ignore hidden directories
885+ if is_hidden (root , options .check_hidden ):
879886 continue
880887 for file_ in files :
881888 # ignore hidden files in directories
882889 if is_hidden (file_ , options .check_hidden ):
883890 continue
884- if glob_match .match (file_ ): # skip files
885- continue
891+ # skip files
892+ try :
893+ if glob_match .match (file_ ):
894+ continue
895+ except re .error :
896+ print ("ERROR: --skip/-S has been fed an invalid glob" ,
897+ file = sys .stderr )
898+ return EX_USAGE
886899 fname = os .path .join (root , file_ )
887- if glob_match .match (fname ): # skip paths
888- continue
900+ # skip paths
901+ try :
902+ if glob_match .match (fname ):
903+ continue
904+ except re .error :
905+ print ("ERROR: --skip/-S has been fed an invalid glob" ,
906+ file = sys .stderr )
907+ return EX_USAGE
908+
889909 bad_count += parse_file (
890910 fname , colors , summary , misspellings , exclude_lines ,
891911 file_opener , word_regex , ignore_word_regex , uri_regex ,
892912 uri_ignore_words , context , options )
893913
894914 # skip (relative) directories
895- dirs [:] = [dir_ for dir_ in dirs if not glob_match .match (dir_ )]
915+ try :
916+ dirs [:] = [
917+ dir_
918+ for dir_ in dirs
919+ if not glob_match .match (dir_ )
920+ ]
921+ except re .error :
922+ print ("ERROR: --skip/-S has been fed an invalid glob" ,
923+ file = sys .stderr )
924+ return EX_USAGE
896925
897926 elif not glob_match .match (filename ): # skip files
898927 bad_count += parse_file (
0 commit comments