From 64ee8f8af864ed11fc3bbf11901151f117582109 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 22 Jul 2013 14:30:49 -0400 Subject: [PATCH] Bug 10625 - Inventory/Stocktaking tool cannot handle windows file uploads The inventory/stocktaking tool interprets windows text editor file as a single large barcode because the text editor only uses carriage returns for line breaks, rather than a carriage return and line break combination. This tools should be able to handle \r, \n, and/or \r\n. Test Plan: 1) Download the attached sample file of barcodes 2) Upload this file to the inventory/stocktaking tool. For this test, it doesn't matter that these barcodes aren't cataloged in your system. 3) Note that the "barcode not found" is a single extremely long barcode 4) Apply this patch 5) Repeat step 2 6) Note that you now get a "barcode not found" error for each barcode individually. Signed-off-by: Mirko Tietgen Signed-off-by: Jonathan Druart --- tools/inventory.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/inventory.pl b/tools/inventory.pl index fdf3161..5c115f1 100755 --- a/tools/inventory.pl +++ b/tools/inventory.pl @@ -21,6 +21,8 @@ use strict; use warnings; +use File::Slurp qw(read_file); + #need to open cgi and get the fh before anything else opens a new cgi context (see C4::Auth) use CGI; my $input = CGI->new; @@ -147,8 +149,12 @@ if ($uploadbarcodes && length($uploadbarcodes)>0){ my $qwthdrawn = $dbh->prepare($strsth); my @errorloop; my $count=0; - while (my $barcode=<$uploadbarcodes>){ - $barcode =~ s/\r?\n$//; + + # This allows us to handle files where lines are delimited by \r, \n, or \r\n. + my $file_contents = read_file( $uploadbarcodes ); + my @barcodes = split( /\r\n|\n|\r/, $file_contents ); + + for my $barcode ( @barcodes ){ if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){ push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1}; }else{ -- 1.7.10.4