Bugzilla – Attachment 130760 Details for
Bug 23873
Allow marc modification templates to use capturing groups in substitutions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23873: Enable capture groups in MarcModificationTemplates
Bug-23873-Enable-capture-groups-in-MarcModificatio.patch (text/plain), 2.45 KB, created by
Nick Clemens (kidclamp)
on 2022-02-17 15:25:34 UTC
(
hide
)
Description:
Bug 23873: Enable capture groups in MarcModificationTemplates
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-02-17 15:25:34 UTC
Size:
2.45 KB
patch
obsolete
>From 89cfa1ed2e636b06d070e42a85745a8a90433051 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 13 Dec 2021 09:59:15 +0000 >Subject: [PATCH] Bug 23873: Enable capture groups in MarcModificationTemplates > >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 > MarcModificationTemplate 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> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/SimpleMARC.pm | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > >diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm >index a501a9441f..6fd08b1013 100644 >--- a/Koha/SimpleMARC.pm >+++ b/Koha/SimpleMARC.pm >@@ -636,6 +636,9 @@ sub _modify_values { > my $regex = $params->{regex}; > > if ( $regex and $regex->{search} ) { >+ my $replace = $regex->{replace}; >+ $replace =~ s/"/\\"/g; # Protection from embedded code >+ $replace = '"' . $replace . '"'; # Put in a string for /ee > $regex->{modifiers} //= q||; > my @available_modifiers = qw( i g ); > my $modifiers = q||; >@@ -645,16 +648,16 @@ sub _modify_values { > } > foreach my $value ( @$values ) { > if ( $modifiers =~ m/^(ig|gi)$/ ) { >- $value =~ s/$regex->{search}/$regex->{replace}/ig; >+ $value =~ s/$regex->{search}/$replace/igee; > } > elsif ( $modifiers eq 'i' ) { >- $value =~ s/$regex->{search}/$regex->{replace}/i; >+ $value =~ s/$regex->{search}/$replace/iee; > } > elsif ( $modifiers eq 'g' ) { >- $value =~ s/$regex->{search}/$regex->{replace}/g; >+ $value =~ s/$regex->{search}/$replace/gee; > } > else { >- $value =~ s/$regex->{search}/$regex->{replace}/; >+ $value =~ s/$regex->{search}/$replace/ee; > } > } > } >-- >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 23873
:
128430
|
128431
|
128432
|
128433
|
128980
|
128981
|
130759
| 130760