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

(-)a/C4/Koha.pm (-2 / +8 lines)
Lines 836-842 sub _isbn_cleanup { Link Here
836
  to be of the specified format.
836
  to be of the specified format.
837
837
838
  If the string cannot be validated as an isbn,
838
  If the string cannot be validated as an isbn,
839
  it returns nothing.
839
  it returns nothing unless return_invalid param is passed.
840
841
  #FIXME This routine (and others?) should be moved to Koha::Util::Normalize
840
842
841
=cut
843
=cut
842
844
Lines 846-851 sub NormalizeISBN { Link Here
846
    my $string        = $params->{isbn};
848
    my $string        = $params->{isbn};
847
    my $strip_hyphens = $params->{strip_hyphens};
849
    my $strip_hyphens = $params->{strip_hyphens};
848
    my $format        = $params->{format};
850
    my $format        = $params->{format};
851
    my $return_invalid = $params->{return_invalid};
849
852
850
    return unless $string;
853
    return unless $string;
851
854
Lines 854-860 sub NormalizeISBN { Link Here
854
    if ( $isbn && $isbn->is_valid() ) {
857
    if ( $isbn && $isbn->is_valid() ) {
855
858
856
        if ( $format eq 'ISBN-10' ) {
859
        if ( $format eq 'ISBN-10' ) {
857
            $isbn = $isbn->as_isbn10();
860
        $isbn = $isbn->as_isbn10();
858
        }
861
        }
859
        elsif ( $format eq 'ISBN-13' ) {
862
        elsif ( $format eq 'ISBN-13' ) {
860
            $isbn = $isbn->as_isbn13();
863
            $isbn = $isbn->as_isbn13();
Lines 868-874 sub NormalizeISBN { Link Here
868
        }
871
        }
869
872
870
        return $string;
873
        return $string;
874
    } elsif ( $return_invalid ) {
875
        return $string;
871
    }
876
    }
877
872
}
878
}
873
879
874
=head2 GetVariationsOfISBN
880
=head2 GetVariationsOfISBN
(-)a/Koha/Util/Normalize.pm (-6 / +8 lines)
Lines 112-123 sub ISBN { Link Here
112
    my ( $string ) = @_;
112
    my ( $string ) = @_;
113
    return if !defined( $string );
113
    return if !defined( $string );
114
114
115
    my $isbn = Business::ISBN->new($string);
115
    my $isbn = C4::Koha::NormalizeISBN({
116
    if (defined $isbn && $isbn->is_valid) {
116
        isbn => $string,
117
        $string = $isbn->as_isbn13->as_string([]);
117
        format => 'ISBN-13',
118
    }
118
        strip_hyphens  => 1,
119
119
        return_invalid => 1,
120
    return $string;
120
    });
121
122
    return $isbn;
121
}
123
}
122
124
123
1;
125
1;
(-)a/t/Koha.t (-2 / +3 lines)
Lines 25-31 use Module::Load::Conditional qw/check_install/; Link Here
25
25
26
BEGIN {
26
BEGIN {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
27
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
28
        plan tests => 38;
28
        plan tests => 39;
29
    } else {
29
    } else {
30
        plan skip_all => "Need Test::DBIx::Class"
30
        plan skip_all => "Need Test::DBIx::Class"
31
    }
31
    }
Lines 81-86 eval { Link Here
81
    $isbn = C4::Koha::NormalizeISBN({ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1 });
81
    $isbn = C4::Koha::NormalizeISBN({ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1 });
82
};
82
};
83
ok($@ eq '', 'NormalizeISBN does not throw exception when parsing invalid ISBN (bug 12243)');
83
ok($@ eq '', 'NormalizeISBN does not throw exception when parsing invalid ISBN (bug 12243)');
84
$isbn = C4::Koha::NormalizeISBN({ isbn => '0788893777 (2 DVD 45th ed)', format => 'ISBN-10', strip_hyphens => 1, return_invalid =>1 });
85
is($isbn, '0788893777 (2 DVD 45th ed)', 'NormalizeISBN returns original string when converting to ISBN10 an ISBN starting with 979 (bug 13167)');
84
86
85
eval {
87
eval {
86
    $isbn = C4::Koha::NormalizeISBN({ isbn => '979-10-90085-00-8', format => 'ISBN-10', strip_hyphens => 1 });
88
    $isbn = C4::Koha::NormalizeISBN({ isbn => '979-10-90085-00-8', format => 'ISBN-10', strip_hyphens => 1 });
87
- 

Return to bug 23324