@@ -871,27 +871,56 @@ def main(*args):
871
871
872
872
if os .path .isdir (filename ):
873
873
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 ):
878
885
continue
879
886
for file_ in files :
880
887
# ignore hidden files in directories
881
888
if is_hidden (file_ , options .check_hidden ):
882
889
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
885
898
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
+
888
908
bad_count += parse_file (
889
909
fname , colors , summary , misspellings , exclude_lines ,
890
910
file_opener , word_regex , ignore_word_regex , uri_regex ,
891
911
uri_ignore_words , context , options )
892
912
893
913
# 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
895
924
896
925
elif not glob_match .match (filename ): # skip files
897
926
bad_count += parse_file (
0 commit comments