Browse Source

Bug 21959: allow only i and g regex modifiers

Signed-off-by: Mathilde Formery <mathilde.formery@ville-nimes.fr>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Alex Arnaud 4 years ago
committed by Martin Renvoize
parent
commit
ae5728020a
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 22
      tools/batchMod.pl

22
tools/batchMod.pl

@ -230,12 +230,28 @@ if ($op eq "action") {
my $tag = $tags[$i];
my $subfield = $subfields[$i];
my $replace = $replaces[$i];
my $mod = $modifiers[$i];
my $value = $localmarcitem->field( $tag )->subfield( $subfield );
my $old_value = $value;
## no critic (StringyEval)
eval "\$value =~ s/$search/$replace/$mod";
my @available_modifiers = qw( i g );
my $retained_modifiers = q||;
for my $modifier ( split //, $modifiers[$i] ) {
$retained_modifiers .= $modifier
if grep {/$modifier/} @available_modifiers;
}
if ( $retained_modifiers =~ m/^(ig|gi)$/ ) {
$value =~ s/$search/$replace/ig;
}
elsif ( $retained_modifiers eq 'i' ) {
$value =~ s/$search/$replace/i;
}
elsif ( $retained_modifiers eq 'g' ) {
$value =~ s/$search/$replace/g;
}
else {
$value =~ s/$search/$replace/;
}
my @fields_to = $localmarcitem->field($tag);
foreach my $field_to_update ( @fields_to ) {

Loading…
Cancel
Save