Bug 30233: (follow-up) Log a warning when _apply_substitution discards a bad pattern

When eval { qr/$pattern/ } fails (e.g. the admin-configured s/// contains
an invalid regex), _apply_substitution previously returned silently with no
indication of why the rule was skipped. Add a Koha::Logger warn so the
failure appears in the log and is diagnosable without a debugger.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-07-01 08:18:13 +01:00 committed by Pedro Amorim
parent b9e7973649
commit 45852aa193
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 5 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package C4::ClassSplitRoutine::RegEx;
use Modern::Perl;
use Koha::Logger;
use Koha::Regex::Replacement;
=head1 NAME
@ -83,7 +84,10 @@ sub _apply_substitution {
my $ci = $flags =~ /i/ ? '(?i)' : '';
my $compiled = eval { qr/$ci$pattern/ };
return unless defined $compiled;
unless ( defined $compiled ) {
Koha::Logger->get->warn("C4::ClassSplitRoutine::RegEx: failed to compile pattern [$pattern]: $@");
return;
}
my $expand = sub { Koha::Regex::Replacement::expand_template( $replacement, [ @{^CAPTURE} ], {%+} ) };