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

(-)a/C4/Biblio.pm (+3 lines)
Lines 93-98 use C4::Charset qw( Link Here
93
    nsb_clean
93
    nsb_clean
94
    SetMarcUnicodeFlag
94
    SetMarcUnicodeFlag
95
    SetUTF8Flag
95
    SetUTF8Flag
96
    StripNonXmlChars
96
);
97
);
97
use C4::Languages;
98
use C4::Languages;
98
use C4::Linker;
99
use C4::Linker;
Lines 2238-2243 sub TransformHtmlToMarc { Link Here
2238
                    ;
2239
                    ;
2239
                    # between 001 and 009 (included)
2240
                    # between 001 and 009 (included)
2240
                } elsif ( $fval ne '' ) {
2241
                } elsif ( $fval ne '' ) {
2242
                    $fval = StripNonXmlChars($fval); #Strip out any non-XML characters like control characters
2241
                    $newfield = MARC::Field->new( $tag, $fval, );
2243
                    $newfield = MARC::Field->new( $tag, $fval, );
2242
                }
2244
                }
2243
2245
Lines 2259-2264 sub TransformHtmlToMarc { Link Here
2259
                        $newfield->add_subfields( $fkey => $fval);
2261
                        $newfield->add_subfields( $fkey => $fval);
2260
                    }
2262
                    }
2261
                    elsif($fval ne '') {
2263
                    elsif($fval ne '') {
2264
                        $fval = StripNonXmlChars($fval); #Strip out any non-XML characters like control characters
2262
                        $newfield = MARC::Field->new( $tag, $ind1, $ind2, $fkey => $fval );
2265
                        $newfield = MARC::Field->new( $tag, $ind1, $ind2, $fkey => $fval );
2263
                    }
2266
                    }
2264
                    $j += 2;
2267
                    $j += 2;
(-)a/t/db_dependent/Biblio/TransformHtmlToMarc.t (-3 / +17 lines)
Lines 22-28 Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); Link Here
22
( $biblionumbertagfield, $biblionumbertagsubfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" );
22
( $biblionumbertagfield, $biblionumbertagsubfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" );
23
23
24
subtest 'Biblio record' => sub {
24
subtest 'Biblio record' => sub {
25
    plan tests => 17;
25
    plan tests => 20;
26
    my $leader = '00203nam a2200097   4500';
26
    my $leader = '00203nam a2200097   4500';
27
    my $input  = CGI->new;
27
    my $input  = CGI->new;
28
    $input->param( -name => 'biblionumber',                                        -value => '42' );
28
    $input->param( -name => 'biblionumber',                                        -value => '42' );
Lines 73-82 subtest 'Biblio record' => sub { Link Here
73
    $input->param( -name => "tag_490_code_b_1123", -value => 'b' );
73
    $input->param( -name => "tag_490_code_b_1123", -value => 'b' );
74
    $input->param( -name => "tag_490_subfield_b_1123", -value => '490b' );
74
    $input->param( -name => "tag_490_subfield_b_1123", -value => '490b' );
75
75
76
    # A field (900) after 490
77
    $input->param( -name => "tag_900_indicator1_1123", -value => "" );
78
    $input->param( -name => "tag_900_indicator2_1123", -value => "" );
79
    $input->param( -name => "tag_900_code_a_1123", -value => 'a' );
80
    $input->param( -name => "tag_900_subfield_a_1123", -value => "This string has bad \x{1B}characters in it" );
81
76
    my $record = C4::Biblio::TransformHtmlToMarc($input, 1);
82
    my $record = C4::Biblio::TransformHtmlToMarc($input, 1);
77
83
78
    my @all_fields = $record->fields;
84
    my @all_fields = $record->fields;
79
    is( @all_fields, 7, 'The record should have been created with 7 fields' );
85
    is( @all_fields, 8, 'The record should have been created with 8 fields' );
80
        # biblionumber + 2x010 + 100 + 200 + 390 + 490
86
        # biblionumber + 2x010 + 100 + 200 + 390 + 490
81
    my @fields_010 = $record->field('010');
87
    my @fields_010 = $record->field('010');
82
    is( @fields_010, 2, 'The record should have been created with 2 010' );
88
    is( @fields_010, 2, 'The record should have been created with 2 010' );
Lines 92-97 subtest 'Biblio record' => sub { Link Here
92
    is( @subfields_200_a, 2, 'The record should have been created with 2 200$a' );
98
    is( @subfields_200_a, 2, 'The record should have been created with 2 200$a' );
93
    is_deeply( \@subfields_200_a, [ 'first title', 'second title' ], 'The 2 titles should have been kept in the correct order' );
99
    is_deeply( \@subfields_200_a, [ 'first title', 'second title' ], 'The 2 titles should have been kept in the correct order' );
94
100
101
    my @fields_900 = $record->field('900');
102
    is( @fields_900, 1, 'The record should have been created with 1 900' );
103
    is_deeply( $fields_900[0]->subfields(), [ 'a', 'This string has bad characters in it' ], 'Field 900 had its non-XML characters stripped');
104
95
    my @subfields_biblionumber = $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield );
105
    my @subfields_biblionumber = $record->subfield( $biblionumbertagfield, $biblionumbertagsubfield );
96
    is( @subfields_biblionumber, 1, 'The record should contain only one biblionumber field' );
106
    is( @subfields_biblionumber, 1, 'The record should contain only one biblionumber field' );
97
107
Lines 105-110 subtest 'Biblio record' => sub { Link Here
105
    is( $all_fields[4]->tag, '390', 'Fifth field is 390' );
115
    is( $all_fields[4]->tag, '390', 'Fifth field is 390' );
106
    is( $all_fields[5]->subfield('a'), 42, 'Sixth field contains bibnumber' );
116
    is( $all_fields[5]->subfield('a'), 42, 'Sixth field contains bibnumber' );
107
    is( $all_fields[6]->tag, '490', 'Last field is 490' );
117
    is( $all_fields[6]->tag, '490', 'Last field is 490' );
118
119
    my $new_record = eval { MARC::Record::new_from_xml( $record->as_xml(), 'UTF-8' ); };
120
    my $record_error = $@;
121
    ok( ! $record_error,'No errors parsing MARCXML generated by TransformHtmlToMarc');
122
108
};
123
};
109
124
110
subtest 'Add authority record' => sub {
125
subtest 'Add authority record' => sub {
111
- 

Return to bug 34549