Bug 28533

Summary: Requesting whole field in 'itemcallnumber' system preference causes internal server error
Product: Koha Reporter: Nick Clemens (kidclamp) <nick>
Component: CatalogingAssignee: Nick Clemens (kidclamp) <nick>
Status: CLOSED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: normal    
Priority: P5 - low CC: fridolin.somers, jonathan.druart, kyle, m.de.rooy, salman.ali, victor
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
21.11.00,21.05.03,20.11.09
Attachments: Bug 28533: Set subfields to 'undef' if whole field request in itemcallnumebr system preference
Bug 28533: Set subfields to 'undef' if whole field request in itemcallnumebr system preference
Bug 28533: Set subfields to 'undef' if whole field request in itemcallnumebr system preference
Bug 28533: Fix other ocurrence

Description Nick Clemens (kidclamp) 2021-06-09 12:59:19 UTC
To recreate:
1 - Set 'itemcallnumber' system preference to 082
2 - Find/Create a record with an 082 field
3 - Add items to the record
4 - Error:
Unmatched [ in regex; marked by <-- HERE in m/^[ <-- HERE ]$/ at /usr/share/perl5/MARC/Field.pm line 643.
Comment 1 Nick Clemens (kidclamp) 2021-06-09 13:06:37 UTC
Created attachment 121738 [details] [review]
Bug 28533: Set subfields to 'undef' if whole field request in itemcallnumebr system preference

This patch undefines the CNsubfields variable when the whole field is requested

Note that the substr returns '' when no characters are found, so we test if the string eq ''

Testing 'truth' doesn't work because "0" is a valid option

To test:
 1 - Edit a record, add an 082 field
     082 0 0 ‡aalpha‡bbeta‡0delta
 2 - Set itemcallnumber system preference to 082
 3 - Attempt to add/edit items
 4 - ISE
 5 - Apply patch, restart all the things
 6 - Add/edit items - no error
 7 - Confirm the itemcallnumber field is populated with "alpha beta delta"
 8 - Set itemcallnumber system preference to '0820'
 9 - Add/edit items
10 - Confirm itemcallnumber is populated with 'delta'
Comment 2 Salman Ali 2021-06-10 18:59:05 UTC
Created attachment 121808 [details] [review]
Bug 28533: Set subfields to 'undef' if whole field request in itemcallnumebr system preference

This patch undefines the CNsubfields variable when the whole field is requested

Note that the substr returns '' when no characters are found, so we test if the string eq ''

Testing 'truth' doesn't work because "0" is a valid option

To test:
 1 - Edit a record, add an 082 field
     082 0 0 ‡aalpha‡bbeta‡0delta
 2 - Set itemcallnumber system preference to 082
 3 - Attempt to add/edit items
 4 - ISE
 5 - Apply patch, restart all the things
 6 - Add/edit items - no error
 7 - Confirm the itemcallnumber field is populated with "alpha beta delta"
 8 - Set itemcallnumber system preference to '0820'
 9 - Add/edit items
10 - Confirm itemcallnumber is populated with 'delta'

Signed-off-by: Salman Ali <salman@outaouais>
Comment 3 Marcel de Rooy 2021-07-16 06:47:34 UTC
        * Signed-off-by line 'Signed-off-by: Salman Ali <salman@outaouais>' seems invalid
Comment 4 Marcel de Rooy 2021-07-16 06:52:13 UTC
Hmm who invented this variable name :)
my $temp = GetMarcBiblio({ biblionumber => $biblionumber });
Comment 5 Marcel de Rooy 2021-07-16 06:58:19 UTC
(In reply to Nick Clemens from comment #0)
> Unmatched [ in regex; marked by <-- HERE in m/^[ <-- HERE ]$/ at
> /usr/share/perl5/MARC/Field.pm line 643.

Looks like Galen has a problem too.
Comment 6 Marcel de Rooy 2021-07-16 06:59:42 UTC
Created attachment 122870 [details] [review]
Bug 28533: Set subfields to 'undef' if whole field request in itemcallnumebr system preference

This patch undefines the CNsubfields variable when the whole field is requested

Note that the substr returns '' when no characters are found, so we test if the string eq ''

Testing 'truth' doesn't work because "0" is a valid option

To test:
 1 - Edit a record, add an 082 field
     082 0 0 ‡aalpha‡bbeta‡0delta
 2 - Set itemcallnumber system preference to 082
 3 - Attempt to add/edit items
 4 - ISE
 5 - Apply patch, restart all the things
 6 - Add/edit items - no error
 7 - Confirm the itemcallnumber field is populated with "alpha beta delta"
 8 - Set itemcallnumber system preference to '0820'
 9 - Add/edit items
10 - Confirm itemcallnumber is populated with 'delta'

Signed-off-by: Salman Ali <salman.ali@inLibro.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 7 Jonathan Druart 2021-07-26 09:07:03 UTC
Same code in C4::Items::PrepareItemrecordDisplay. It certainly needs to be adjusted too.
Comment 8 Nick Clemens (kidclamp) 2021-07-30 19:20:58 UTC
Created attachment 123343 [details] [review]
Bug 28533: Fix other ocurrence
Comment 9 Jonathan Druart 2021-08-06 10:14:53 UTC
Pushed to master for 21.11, thanks to everybody involved!
Comment 10 Kyle M Hall 2021-08-06 15:12:12 UTC
Pushed to 21.05.x for 21.05.03
Comment 11 Fridolin Somers 2021-08-11 20:00:12 UTC
Pushed to 20.11.x for 20.11.09
Comment 12 Victor Grousset/tuxayo 2021-08-16 21:05:52 UTC
Not backported to oldoldstable (20.05.x). Feel free to ask if it's needed.
Comment 13 Jonathan Druart 2021-10-06 13:07:40 UTC
[Just saying...
Got a conflict with this patch when rebasing bug 28533. It clearly shows that the work done is very useful: 1. the need to centralize the code and 2. have test coverage for ANY changes we are making there.]