Bugzilla – Attachment 151210 Details for
Bug 30358
Strip leading/trailing whitespace characters from input fields when cataloguing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30358: (follow-up) stripWhitespaceChars subroutine and tests
Bug-30358-follow-up-stripWhitespaceChars-subroutin.patch (text/plain), 4.57 KB, created by
Katrin Fischer
on 2023-05-15 18:05:31 UTC
(
hide
)
Description:
Bug 30358: (follow-up) stripWhitespaceChars subroutine and tests
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2023-05-15 18:05:31 UTC
Size:
4.57 KB
patch
obsolete
>From 930cdd168e17c30b906fbb970c1c3f4da1d72174 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Mon, 15 Aug 2022 16:48:55 +1200 >Subject: [PATCH] Bug 30358: (follow-up) stripWhitespaceChars subroutine and > tests > >To test: > >Confirm test plan above still works as expected and tests pass in >t/Koha_MetadataRecord.t > >Sponsored-by: Catalyst IT > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > C4/AuthoritiesMarc.pm | 11 +---------- > C4/Biblio.pm | 11 +---------- > Koha/MetadataRecord.pm | 25 +++++++++++++++++++++++++ > t/Koha_MetadataRecord.t | 23 ++++++++++++++++++++++- > 4 files changed, 49 insertions(+), 21 deletions(-) > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index 9f5430d45f..d21e7c059c 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -659,16 +659,7 @@ sub AddAuthority { > } > > if ( C4::Context->preference('StripWhitespaceChars') ) { >- foreach my $field ( $record->fields ) { >- foreach my $subfield ( $field->subfields ) { >- my $key = $subfield->[0]; >- my $value = $subfield->[1]; >- $value =~ s/[\n\r]+/ /g; >- $value =~ s/^\s+|\s+$|^\t+|\t+$//g; >- $field->add_subfields( $key => $value ); # add subfield to the end of the subfield list >- $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list >- } >- } >+ $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); > } > > # Save record into auth_header, update 001 >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 3277bf358d..8297f31c81 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -2812,16 +2812,7 @@ sub ModBiblioMarc { > } > > if ( C4::Context->preference('StripWhitespaceChars') ) { >- foreach my $field ( $record->fields ) { >- foreach my $subfield ( $field->subfields ) { >- my $key = $subfield->[0]; >- my $value = $subfield->[1]; >- $value =~ s/[\n\r]+/ /g; >- $value =~ s/^\s+|\s+$|^\t+|\t+$//g; >- $field->add_subfields( $key => $value ); # add subfield to the end of the subfield list >- $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list >- } >- } >+ $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); > } > > my $metadata = { >diff --git a/Koha/MetadataRecord.pm b/Koha/MetadataRecord.pm >index 6f0aa1fb4b..80e8ecdd48 100644 >--- a/Koha/MetadataRecord.pm >+++ b/Koha/MetadataRecord.pm >@@ -108,4 +108,29 @@ sub createMergeHash { > } > } > >+=head2 stripWhitespaceChars >+ >+ $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); >+ >+Strip leading and trailing whitespace characters from input fields. >+ >+=cut >+ >+sub stripWhitespaceChars { >+ my ( $record ) = @_; >+ >+ foreach my $field ( $record->fields ) { >+ foreach my $subfield ( $field->subfields ) { >+ my $key = $subfield->[0]; >+ my $value = $subfield->[1]; >+ $value =~ s/[\n\r]+/ /g; >+ $value =~ s/^\s+|\s+$|^\t+|\t+$//g; >+ $field->add_subfields( $key => $value ); # add subfield to the end of the subfield list >+ $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list >+ } >+ } >+ >+ return $record; >+} >+ > 1; >diff --git a/t/Koha_MetadataRecord.t b/t/Koha_MetadataRecord.t >index 0bcc4690dc..7202f4a86f 100755 >--- a/t/Koha_MetadataRecord.t >+++ b/t/Koha_MetadataRecord.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > use Test::Warn; > > use MARC::Record; >@@ -143,3 +143,24 @@ subtest "new() tests" => sub { > is( $metadata_record, undef, 'record object mandatory') > }; > >+subtest "stripWhitespaceChars() tests" => sub { >+ plan tests => 2; >+ >+ # Test default values with a MARC::Record record >+ my $record = MARC::Record->new(); >+ >+ $record->add_fields( >+ [ '001', '1234' ], >+ [ '150', ' ', ' ', a => 'Test' ], >+ [ '520', ' ', ' ', a => "This is\na test!\t" ], >+ [ '521', ' ', ' ', a => "This is a\t test!\t" ], >+ ); >+ >+ $record = Koha::MetadataRecord::stripWhitespaceChars( $record ); >+ >+ my $get520a = $record->subfield('520','a'); >+ is( $get520a, "This is a test!", "Whitespace characters are appropriately stripped or replaced with spaces" ); >+ >+ my $get521a = $record->subfield('521','a'); >+ is( $get521a, "This is a\t test!", "Trailing tabs are stripped while inner tabs are kept" ); >+}; >-- >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 30358
:
132202
|
132275
|
132919
|
133055
|
133056
|
133140
|
133224
|
133225
|
134195
|
134453
|
137451
|
137452
|
137453
|
137454
|
137455
|
137456
|
137457
|
139110
|
142905
|
142906
|
142907
|
142908
|
142909
|
142910
|
142911
|
142912
|
143053
|
143057
|
143058
|
143059
|
143060
|
143061
|
143062
|
143063
|
143064
|
143065
|
144120
|
144121
|
144122
|
144123
|
144124
|
144125
|
144126
|
144127
|
144128
|
144129
|
144130
|
144171
|
145308
|
145309
|
145310
|
145311
|
145312
|
145313
|
145314
|
145315
|
145316
|
145317
|
145318
|
151202
|
151203
|
151204
|
151205
|
151206
|
151207
|
151208
| 151210 |
151212
|
151214
|
151215