Bugzilla – Attachment 129574 Details for
Bug 29781
Allow item batch modification to use capturing groups in regex option
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29781: Enable capture groups in batch item modification
Bug-29781-Enable-capture-groups-in-batch-item-modi.patch (text/plain), 2.61 KB, created by
Andrew Fuerste-Henry
on 2022-01-18 14:50:45 UTC
(
hide
)
Description:
Bug 29781: Enable capture groups in batch item modification
Filename:
MIME Type:
Creator:
Andrew Fuerste-Henry
Created:
2022-01-18 14:50:45 UTC
Size:
2.61 KB
patch
obsolete
>From 600b864452910ecf6c98bd28b88a282e9cb68941 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 17 Jan 2022 13:38:28 +0000 >Subject: [PATCH] Bug 29781: Enable capture groups in batch item modification > >This patch adds support for regular expression capture groups in >MarcModificationTemplates. > >We escape double quotes in the replacement string, then quote the whole >string before applying the `ee` modifier to the final regex >application. > >See https://blog.james.rcpt.to/2010/10/25/perl-search-and-replace-using-variables/ >for further details. > >Test plan >1) Attempt to use capture groups in your regular expression based > batch item modification and note it does not work. >2) Apply the patch and try again, this time the capture group > should yield the expected results. >3) Run t/SimpleMARC.t and confirm the tests still pass. > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> >--- > Koha/Items.pm | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > >diff --git a/Koha/Items.pm b/Koha/Items.pm >index 0730935a0b..551564d8b9 100644 >--- a/Koha/Items.pm >+++ b/Koha/Items.pm >@@ -363,13 +363,17 @@ sub batch_update { > return ( { modified_itemnumbers => \@modified_itemnumbers, modified_fields => $modified_fields }, $self ); > } > >-sub apply_regex { # FIXME Should be moved outside of Koha::Items >+sub apply_regex { >+ # FIXME Should be moved outside of Koha::Items >+ # FIXME This is nearly identical to Koha::SimpleMARC::_modify_values > my ($params) = @_; > my $search = $params->{search}; > my $replace = $params->{replace}; > my $modifiers = $params->{modifiers} || q{}; > my $value = $params->{value}; > >+ $replace =~ s/"/\\"/g; # Protection from embedded code >+ $replace = '"' . $replace . '"'; # Put in a string for /ee > my @available_modifiers = qw( i g ); > my $retained_modifiers = q||; > for my $modifier ( split //, $modifiers ) { >@@ -377,16 +381,16 @@ sub apply_regex { # FIXME Should be moved outside of Koha::Items > if grep { /$modifier/ } @available_modifiers; > } > if ( $retained_modifiers =~ m/^(ig|gi)$/ ) { >- $value =~ s/$search/$replace/ig; >+ $value =~ s/$search/$replace/igee; > } > elsif ( $retained_modifiers eq 'i' ) { >- $value =~ s/$search/$replace/i; >+ $value =~ s/$search/$replace/iee; > } > elsif ( $retained_modifiers eq 'g' ) { >- $value =~ s/$search/$replace/g; >+ $value =~ s/$search/$replace/gee; > } > else { >- $value =~ s/$search/$replace/; >+ $value =~ s/$search/$replace/ee; > } > > return $value; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29781
:
129526
|
129527
|
129528
|
129529
|
129573
|
129574
|
130498
|
130499
|
130508
|
130509