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