From 52e6f981012125953e6c46611307215c74b24bdf Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 17 Jan 2017 09:14:00 +0100 Subject: [PATCH] Bug 17915 - warning in Stage MARC records for import when matching rule with offset When using Stage MARC records for import with a matching rule where an offset is defined, the input string may be empty or shorter than the offset. This generated a warning : stage-marc-import.pl: substr outside of string at /home/koha/src/C4/Matcher.pm line 822. Test plan : - define a matching rule on ISBN with length 0 and offset 999 (too big for any value) - import some MARC records with this matching rule - check the perl warns => Without patch you see warns : "substr outside of string at /home/koha/src/C4/Matcher.pm" => With patch no such warn - edit the matching rule to set offset 0 - import some MARC records, with matching ISBN, with this matching rule => Import must match existing records with same ISBN --- C4/Matcher.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/C4/Matcher.pm b/C4/Matcher.pm index 40e6e5f..92549a7 100644 --- a/C4/Matcher.pm +++ b/C4/Matcher.pm @@ -816,7 +816,9 @@ sub _get_match_keys { ); } - if ($component->{'length'}>0) { + if ( $component->{'offset'} > length($string) ) { + $string = ''; + } elsif ($component->{'length'}>0) { $string= substr($string, $component->{'offset'}, $component->{'length'}); } elsif ($component->{'offset'}) { $string= substr($string, $component->{'offset'}); -- 2.7.4