From ae5728020ae7ab5330d191a8800fc32aadc1125a Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Tue, 2 Apr 2019 16:14:39 +0200 Subject: [PATCH] Bug 21959: allow only i and g regex modifiers Signed-off-by: Mathilde Formery Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- tools/batchMod.pl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 7077ca277f..65a25d1c7d 100755 --- a/tools/batchMod.pl +++ b/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 ) { -- 2.39.5