From d2fb283fc38390be38a2b500232b90b34300c2ee Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 4 Mar 2026 11:23:46 +0100 Subject: [PATCH] Bug 38365: Use Koha::Devel::Files->ls_tt_files in add_csp_nonces.pl --- misc/devel/add_csp_nonces.pl | 37 +++++++----------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/misc/devel/add_csp_nonces.pl b/misc/devel/add_csp_nonces.pl index 5b307638ccf..7ba655ba73e 100755 --- a/misc/devel/add_csp_nonces.pl +++ b/misc/devel/add_csp_nonces.pl @@ -49,10 +49,11 @@ The script: use Modern::Perl; use Carp qw( carp ); -use File::Find; use Getopt::Long; use Pod::Usage; +use Koha::Devel::Files; + my $apply = 0; my $verbose = 0; my $help = 0; @@ -70,35 +71,15 @@ pod2usage(1) if $help; # The nonce attribute to add my $nonce_attr = 'nonce="[% Koha.CSPNonce | $raw %]"'; -# Patterns to skip (library files, etc.) -my @skip_patterns = ( - qr{/lib/}, # Third-party libraries - qr{/vendor/}, # Vendor files - qr{\.min\.}, # Minified files - qr{/node_modules/}, # Node modules -); - my %stats = ( files_scanned => 0, files_modified => 0, tags_modified => 0, ); -sub should_skip_file { - my ($file) = @_; - for my $pattern (@skip_patterns) { - return 1 if $file =~ $pattern; - } - return 0; -} - sub process_file { my ($file) = @_; - return unless -f $file; - return unless $file =~ /\.(tt|inc)$/; - return if should_skip_file($file); - $stats{files_scanned}++; open my $fh, '<:encoding(UTF-8)', $file or do { @@ -174,15 +155,11 @@ sub process_file { } # Find and process all template files -find( - { - wanted => sub { - process_file($File::Find::name); - }, - no_chdir => 1, - }, - $dir -); +my $dev_files = Koha::Devel::Files->new; +my @tt_files = $dev_files->ls_tt_files; +for my $file (@tt_files) { + process_file($file); +} # Print summary say ""; -- 2.43.0