From 0564c5587be597fbec57e7cfd7ebaffbc3feeb1e Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Sat, 26 Jul 2025 18:02:41 +0300 Subject: [PATCH 1/2] Fix inclusion of excluded type defined with --type-set --- MANIFEST | 1 + lib/App/Ack/ConfigLoader.pm | 3 +++ t/ack-type.yaml | 20 ++++++++++++++++++++ t/yaml.t | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 t/ack-type.yaml diff --git a/MANIFEST b/MANIFEST index 48308d79..a8a06ce4 100644 --- a/MANIFEST +++ b/MANIFEST @@ -69,6 +69,7 @@ t/ack-s.yaml t/ack-show-types.t t/ack-type-del.t t/ack-type.t +t/ack-type.yaml t/ack-v.yaml t/ack-version.t t/ack-w.t diff --git a/lib/App/Ack/ConfigLoader.pm b/lib/App/Ack/ConfigLoader.pm index 4c198cbf..b9b97a86 100644 --- a/lib/App/Ack/ConfigLoader.pm +++ b/lib/App/Ack/ConfigLoader.pm @@ -176,6 +176,9 @@ sub _process_filetypes { if ( not $value ) { @filters = map { $_->invert() } @filters; } + else { + _uninvert_filter( $opt, @filters ); + } push @{ $opt->{'filters'} }, @filters; }; diff --git a/t/ack-type.yaml b/t/ack-type.yaml new file mode 100644 index 00000000..b01125b0 --- /dev/null +++ b/t/ack-type.yaml @@ -0,0 +1,20 @@ +--- +name: --type-set and exclude +args: >- + --ignore-ack-defaults + --type-set=cmake:is:CMakeLists.txt + --type=nocmake + -k -f t/swamp +exitcode: 1 +stderr: '' +stdout: '' + +--- +name: --type-set and override exclusion +args: >- + --ignore-ack-defaults + --type-set=cmake:is:CMakeLists.txt + --type=nocmake + -t cmake -f t/swamp +stdout: | + t/swamp/CMakeLists.txt diff --git a/t/yaml.t b/t/yaml.t index 60031968..f8a9c3e9 100644 --- a/t/yaml.t +++ b/t/yaml.t @@ -3,7 +3,7 @@ use warnings; use strict; -use Test::More tests => 26; +use Test::More tests => 27; use lib 't'; use Util; From ae25a78b0b16394dfdf817aa5a319e4b81e51e4b Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Tue, 12 Aug 2025 19:25:18 +0300 Subject: [PATCH 2/2] Fix inclusion of excluded type with multiple filters --- lib/App/Ack/ConfigLoader.pm | 5 +++-- t/ack-type.yaml | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/App/Ack/ConfigLoader.pm b/lib/App/Ack/ConfigLoader.pm index b9b97a86..14accbe5 100644 --- a/lib/App/Ack/ConfigLoader.pm +++ b/lib/App/Ack/ConfigLoader.pm @@ -124,8 +124,9 @@ sub _uninvert_filter { for ( my $i = 0; $i < @{ $opt->{filters} }; $i++ ) { my $opt_filter = @{ $opt->{filters} }[$i]; - # XXX Do a real list comparison? This just checks string equivalence. - if ( $opt_filter->is_inverted() && "$opt_filter->{filter}" eq "@filters" ) { + if ( $opt_filter->is_inverted() + && grep { $_ == $opt_filter->{filter} } @filters ) + { splice @{ $opt->{filters} }, $i, 1; $i--; } diff --git a/t/ack-type.yaml b/t/ack-type.yaml index b01125b0..ef89fcea 100644 --- a/t/ack-type.yaml +++ b/t/ack-type.yaml @@ -18,3 +18,27 @@ args: >- -t cmake -f t/swamp stdout: | t/swamp/CMakeLists.txt + +--- +name: --type-set, --type-add, and exclude +args: >- + --ignore-ack-defaults + --type-set=cmake:is:CMakeLists.txt + --type-add=cmake:ext:cmake + --type=nocmake + -k -f t/swamp +exitcode: 1 +stderr: '' +stdout: '' + +--- +name: --type-set, --type-add, and override exclusion +args: >- + --ignore-ack-defaults + --type-set=cmake:is:CMakeLists.txt + --type-add=cmake:ext:cmake + --type=nocmake + -t cmake -f t/swamp +stdout: | + t/swamp/CMakeLists.txt + t/swamp/stuff.cmake