View | Details | Raw Unified | Return to bug 30358
Collapse All | Expand All

(-)a/Koha/MetadataRecord.pm (-7 / +9 lines)
Lines 120-132 sub stripWhitespaceChars { Link Here
120
    my ( $record ) = @_;
120
    my ( $record ) = @_;
121
121
122
    foreach my $field ( $record->fields ) {
122
    foreach my $field ( $record->fields ) {
123
        foreach my $subfield ( $field->subfields ) {
123
        unless ( $field->is_control_field ) {
124
            my $key = $subfield->[0];
124
            foreach my $subfield ( $field->subfields ) {
125
            my $value = $subfield->[1];
125
                my $key = $subfield->[0];
126
            $value =~ s/[\n\r]+/ /g;
126
                my $value = $subfield->[1];
127
            $value =~ s/^\s+|\s+$|^\t+|\t+$//g;
127
                $value =~ s/[\n\r]+/ /g;
128
            $field->add_subfields( $key => $value ); # add subfield to the end of the subfield list
128
                $value =~ s/^\s+|\s+$|^\t+|\t+$//g;
129
            $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list
129
                $field->add_subfields( $key => $value ); # add subfield to the end of the subfield list
130
                $field->delete_subfield( pos => 0 ); # delete the subfield at the top of the subfield list
131
            }
130
        }
132
        }
131
    }
133
    }
132
134
(-)a/t/db_dependent/Biblio/ModBiblioMarc.t (-2 / +5 lines)
Lines 48-54 subtest "Check MARC field length calculation" => sub { Link Here
48
};
48
};
49
49
50
subtest "StripWhitespaceChars tests" => sub {
50
subtest "StripWhitespaceChars tests" => sub {
51
    plan tests => 3;
51
    plan tests => 4;
52
52
53
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
53
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
54
    t::lib::Mocks::mock_preference('StripWhitespaceChars', 0);
54
    t::lib::Mocks::mock_preference('StripWhitespaceChars', 0);
Lines 56-61 subtest "StripWhitespaceChars tests" => sub { Link Here
56
    my $biblio = t::lib::TestBuilder->new->build_sample_biblio;
56
    my $biblio = t::lib::TestBuilder->new->build_sample_biblio;
57
    my $record = MARC::Record->new;
57
    my $record = MARC::Record->new;
58
    $record->append_fields(
58
    $record->append_fields(
59
        MARC::Field->new( '003', "abcdefg\n" ),
59
        MARC::Field->new( '245', '', '', a => "  My\ntitle\n" ),
60
        MARC::Field->new( '245', '', '', a => "  My\ntitle\n" ),
60
    );
61
    );
61
62
Lines 75-80 subtest "StripWhitespaceChars tests" => sub { Link Here
75
    my $amendedrec = $biblio->metadata->record;
76
    my $amendedrec = $biblio->metadata->record;
76
    my $amendedtitle = $amendedrec->title;
77
    my $amendedtitle = $amendedrec->title;
77
    is( $amendedtitle, "My title", "Whitespace characters removed from title because StripWhitespaceChars is enabled" );
78
    is( $amendedtitle, "My title", "Whitespace characters removed from title because StripWhitespaceChars is enabled" );
79
80
    my $f003 = $record->field('003')->data;
81
    is( $f003, "abcdefg\n", "Whitespace characters are not stripped from control fields" );
78
};
82
};
79
83
80
$schema->storage->txn_rollback;
84
$schema->storage->txn_rollback;
81
- 

Return to bug 30358