@@ -29,7 +29,6 @@ use File::Path ();
2929use File::Slurp ();
3030use IO::Handle ();
3131use Fcntl qw( :flock SEEK_END) ;
32- use Test::More;
3332
3433use FindBin;
3534use utf8;
@@ -264,6 +263,7 @@ sub do_search ( $self, %opts ) {
264263 is_incomplete => $cache -> {is_incomplete } || 0,
265264 search_in_progress => $cache -> {search_in_progress } || 0,
266265 match => $cache -> {match },
266+ adjusted_request => $cache -> {adjusted_request } // {},
267267 results => $output ,
268268 time_elapsed => $elapsed ,
269269 is_a_known_distro => $is_a_known_distro ,
@@ -585,6 +585,23 @@ sub _load_cache ( $self, $cache_file ) {
585585 return Sereal::read_sereal($cache_file );
586586}
587587
588+ sub _parse_and_check_query_filetype ( $self , $query_filetype , $adjusted_request ={} ) {
589+
590+ my $rules = $self -> _parse_query_filetype($query_filetype );
591+
592+ my $r = $rules // [];
593+ my $value = join ( ' ,' , @$r );
594+ $query_filetype =~ s {\s +} {} g ;
595+ if ( $query_filetype ne $value ) {
596+ $adjusted_request -> {' qft' } = {
597+ error => " Incorrect search filter: invalid characters - $query_filetype " ,
598+ value => $value ,
599+ }
600+ }
601+
602+ return $rules ;
603+ }
604+
588605sub _parse_query_filetype ( $self , $query_filetype ) {
589606
590607 return unless defined $query_filetype ;
@@ -600,6 +617,23 @@ sub _parse_query_filetype ( $self, $query_filetype ) {
600617 return \@filetypes ;
601618}
602619
620+ sub _parse_and_check_ignore_files ( $self , $ignore_files , $adjusted_request ={} ) {
621+
622+ return unless length $ignore_files ;
623+
624+ my $rules = $self -> _parse_ignore_files($ignore_files );
625+
626+ if ( ! $rules ) {
627+ $adjusted_request -> {' qifl' } = {
628+ error => " Incorrect ignore files: invalid characters." ,
629+ value => $ignore_files , # not updated
630+ }
631+ }
632+
633+ return $rules ;
634+ }
635+
636+
603637# convert a string of patterns (file to exclude) to a list of git rules to ignore the path
604638# t/*, *.md, *.json, *.yaml, *.yml, *.conf, cpanfile, LICENSE, MANIFEST, INSTALL, Changes, Makefile.PL, Build.PL, Copying, *.SKIP, *.ini, README
605639sub _parse_ignore_files ( $self , $ignore_files ) {
@@ -652,6 +686,8 @@ sub _get_match_cache(
652686 return $load if $load ;
653687 }
654688
689+ my $adjusted_request = {};
690+
655691 $search_distro =~ s { ::+} { -} g if defined $search_distro ;
656692
657693 # the distro can either come from url or the query with some glob
@@ -668,7 +704,7 @@ sub _get_match_cache(
668704 }
669705
670706 # filter on some type files distro + query filetype
671- if ( my $rules = $self -> _parse_query_filetype ($query_filetype ) ) {
707+ if ( my $rules = $self -> _parse_and_check_query_filetype ($query_filetype , $adjusted_request ) ) {
672708 my $base_search = $git_cmd [-1];
673709 my $is_first_rule = 1;
674710 foreach my $rule (@$rules ) {
@@ -685,7 +721,7 @@ sub _get_match_cache(
685721 }
686722 }
687723
688- if ( my $rules = $self -> _parse_ignore_files ($ignore_files ) ) {
724+ if ( my $rules = $self -> _parse_and_check_ignore_files ($ignore_files , $adjusted_request ) ) {
689725 push @git_cmd , $rules -> @*;
690726 }
691727
@@ -710,8 +746,8 @@ sub _get_match_cache(
710746 # remove the final marker if there
711747 my $search_in_progress = 1;
712748
713- # note "LAST LINE .... " . $list_files->[-1];
714- # note " check ? ", $list_files->[-1] eq END_OF_FILE_MARKER() ? 1 : 0;
749+ # say "LAST LINE .... " . $list_files->[-1];
750+ # say " check ? ", $list_files->[-1] eq END_OF_FILE_MARKER() ? 1 : 0;
715751 if ( scalar @$list_files && $list_files -> [-1] eq END_OF_FILE_MARKER() ) {
716752 pop @$list_files ;
717753 $search_in_progress = 0;
@@ -744,10 +780,11 @@ sub _get_match_cache(
744780 files => $match_files ,
745781 distros => scalar keys $cache -> {distros }-> %*,
746782 };
783+ $cache -> {adjusted_request } = $adjusted_request ;
747784
748785 if ( !$search_in_progress ) {
749786
750- # note "Search in progress..... done caching yaml file";
787+ # say "Search in progress..... done caching yaml file";
751788 $self -> _save_cache( $request_cache_file , $cache );
752789 $self -> _save_cache( $cache_file , $cache );
753790 unlink $raw_cache_file if -e $raw_cache_file ;
@@ -794,7 +831,7 @@ sub run_git_cmd_limit ( $self, %opts ) {
794831 }
795832 else {
796833 # return the content of our current cache from previous run
797- # note "use our cache from previous run";
834+ # say "use our cache from previous run";
798835 my @from_cache = File::Slurp::read_file($cache_file );
799836 chomp @from_cache ;
800837 return \@from_cache ;
@@ -829,7 +866,7 @@ sub run_git_cmd_limit ( $self, %opts ) {
829866 push @lines , $line ;
830867 last if ++$c > $limit ;
831868
832- # note "GOT: $line ", $line eq END_OF_FILE_MARKER() ? 1 : 0;
869+ # say "GOT: $line ", $line eq END_OF_FILE_MARKER() ? 1 : 0;
833870 last if $line eq END_OF_FILE_MARKER();
834871 }
835872 alarm(0);
@@ -892,8 +929,8 @@ sub run_git_cmd_limit ( $self, %opts ) {
892929 exit 42;
893930 }
894931
895- note " Running in kid command: " . join ( ' ' , ' git' , @$cmd );
896- note " KID is caching to file " , $cache_file ;
932+ say " Running in kid command: " . join ( ' ' , ' git' , @$cmd );
933+ say " KID is caching to file " , $cache_file ;
897934
898935 my $to_cache ;
899936
@@ -921,7 +958,7 @@ sub run_git_cmd_limit ( $self, %opts ) {
921958 qq{ \n } ; # in case of the last line did not had a newline
922959 print {$to_cache } END_OF_FILE_MARKER() . qq{ \n } if $cache_file ;
923960 print {$CW } END_OF_FILE_MARKER() . qq{ \n } if $can_write_to_pipe ;
924- note " -- Request finished by kid: $counter lines - "
961+ say " -- Request finished by kid: $counter lines - "
925962 . join ( ' ' , ' git' , @$cmd );
926963 exit $? ;
927964 }
0 commit comments