Bug 20972

Summary: If ISBN has 10 numbers only the first 9 numbers are used
Product: Koha Reporter: Johan Larsson <johan.larsson>
Component: AcquisitionsAssignee: Bugs List <koha-bugs>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: critical    
Priority: P5 - low CC: colin.campbell, fridolin.somers, jonathan.druart, katrin.fischer, martin.renvoize, nick
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on: 7736    
Bug Blocks:    
Attachments: Bug 20972: If ISBN has 10 numbers only the first 9 numbers are used
Signed off patch correcting ISBN extraction
Add a test case for this to Ediorder.t
Bug 20972: If ISBN has 10 numbers only the first 9 numbers are used
Bug 20972: Add a testcase for bug 20972

Description Johan Larsson 2018-06-21 08:44:32 UTC
If ISBN has 10 numbers only the first 9 numbers are being added to the Edifact-message (PIA+5+3540556753:IB') 

The bug is located in Koha/Edifact/Order.pm

     elsif ( $isbn_field =~ m/(\d{9})[Xx\d]/ ) {
         $product_id   = $1; 
         $product_code = 'IB';
     }

product_id will only get the first 9 chars in the regular expression because of the placement on the parenthesis. 

The solution to this is to move the right parenthesis like below:
     elsif ( $isbn_field =~ m/(\d{9}[Xx\d])/ ) {
         $product_id   = $1; 
         $product_code = 'IB';
     }
Comment 1 Johan Larsson 2018-06-21 09:11:14 UTC
Created attachment 76225 [details] [review]
Bug 20972: If ISBN has 10 numbers only the first 9 numbers are used

If ISBN has 10 numbers only the first 9 numbers are being added to the Edifact-message (PIA+5+3540556753:IB')

This is caused by wrong positioning of capturing parentheses in a regular expression.

Sponsored-by: Gothenburg University Library
Comment 2 Colin Campbell 2018-06-22 13:52:09 UTC
Created attachment 76281 [details] [review]
Signed off patch correcting ISBN extraction

Signed off patch
Comment 3 Colin Campbell 2018-06-22 14:15:10 UTC
Created attachment 76290 [details] [review]
Add a test case for this to Ediorder.t

Add a test for this bug and ensure routine is correctly distinguishing 10 character ISBNs from 13 digit EANs
Comment 4 Katrin Fischer 2018-06-22 19:21:55 UTC
Thx for the quick sign-off and tests, Colin!
Comment 5 Katrin Fischer 2018-06-22 19:26:52 UTC
Created attachment 76303 [details] [review]
Bug 20972: If ISBN has 10 numbers only the first 9 numbers are used

If ISBN has 10 numbers only the first 9 numbers are being added to the Edifact-message (PIA+5+3540556753:IB')

This is caused by wrong positioning of capturing parentheses in a regular expression.

Sponsored-by: Gothenburg University Library
Signed-off-by: Colin Campbell <colin.campbell@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 6 Katrin Fischer 2018-06-22 19:26:56 UTC
Created attachment 76304 [details] [review]
Bug 20972: Add a testcase for bug 20972

Ensure all 10 characters of ISBN are preserved

And that ISBNs and EANs are correctly identidied in the PIA segment

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 7 Nick Clemens 2018-06-22 22:04:57 UTC
Awesome work all!

Pushed to master for 18.11.x
Comment 8 Martin Renvoize 2018-06-27 10:32:40 UTC
Pushed to 18.05.x for 18.05.02
Comment 9 Fridolin Somers 2018-06-28 08:44:52 UTC
Pushed to 17.11.x for 17.11.08

Regular expression are a curse, they can be hell or heaven :D
Comment 10 Fridolin Somers 2018-09-24 12:58:01 UTC
Pushed to 17.05.x for 17.05.14