Bug 22204 - Leading spaces in barcode should not allowed in cataloguing
Summary: Leading spaces in barcode should not allowed in cataloguing
Status: RESOLVED DUPLICATE of bug 30409
Alias: None
Product: Koha
Classification: Unclassified
Component: Cataloging (show other bugs)
Version: 21.05
Hardware: All All
: P5 - low major (vote)
Assignee: Jérémy Breuillard
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-24 16:48 UTC by Fridolin Somers
Modified: 2022-04-28 02:53 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 22204: Remove whitespaces in barcode before saving (1.92 KB, patch)
2021-10-14 10:38 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 22204: use barcodedecode from C4/Circulation in additem.pl (1.64 KB, patch)
2021-10-15 14:41 UTC, Jérémy Breuillard
Details | Diff | Splinter Review
[21.05] Bug 22204: Use barcodedecode in additem.pl (1.95 KB, patch)
2021-10-18 11:46 UTC, Julian Maurice
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Fridolin Somers 2019-01-24 16:48:37 UTC
When creating a new item, it is not allowed to add trailing spaces, it shows 'Barcode must be unique'.
But it is allowed to use leading spaces :(
In this case since circulation does a trim on barcode this item can not be checked-out.
It also allows duplicates even with UNIQUE KEY constraint.
Comment 1 Jonathan Druart 2019-12-12 09:55:13 UTC
Hi Frido, do you plan to provide a patch?
Comment 2 Fridolin Somers 2020-01-21 11:28:06 UTC
(In reply to Jonathan Druart from comment #1)
> Hi Frido, do you plan to provide a patch?

I'm not sure when I can find time, feel free to propose patches.
Comment 3 Julian Maurice 2021-10-14 10:38:29 UTC
Created attachment 126266 [details] [review]
Bug 22204: Remove whitespaces in barcode before saving

Test plan:
1. Create an item with barcode "1"
2. Try to create an item with barcode "   1   " and verify that it is
   blocked
3. Create an item with barcode "  XXXXX  " and verify that it is saved
   without spaces in database:
   SELECT barcode FROM items WHERE barcode LIKE '%XXXXX%'

Co-authored-by: Jérémy Breuillard <jeremy.breuillard@biblibre.com>
Comment 4 Marcel de Rooy 2021-10-14 11:27:46 UTC
Please have a look at:
C4/Circulation.pm:      barcodedecode
Comment 5 Marcel de Rooy 2021-10-14 11:28:02 UTC
Please enter assignee too :)
Comment 6 Fridolin Somers 2021-10-15 07:20:55 UTC
BTW : should the trim be in Koha::Items->store() ?
Comment 7 Jérémy Breuillard 2021-10-15 14:41:45 UTC
Created attachment 126344 [details] [review]
Bug 22204: use barcodedecode from C4/Circulation in additem.pl
Comment 8 Jonathan Druart 2021-10-15 14:50:06 UTC
194     $item->barcode(barcodedecode($item->barcode));

Is this patch really needed?

Did you try itemBarcodeInputFilter=whitespace?
Comment 9 Julian Maurice 2021-10-15 15:06:10 UTC
(In reply to Jonathan Druart from comment #8)
> 194     $item->barcode(barcodedecode($item->barcode));
> 
> Is this patch really needed?
> 
> Did you try itemBarcodeInputFilter=whitespace?

It looks like we worked on an out-of-date master branch... (this line was added 10 days ago).

We must try to reproduce the bug on master (bug 26351)
Comment 10 Julian Maurice 2021-10-15 15:08:25 UTC
(In reply to Julian Maurice from comment #9)
> (In reply to Jonathan Druart from comment #8)
> > 194     $item->barcode(barcodedecode($item->barcode));
> > 
> > Is this patch really needed?
> > 
> > Did you try itemBarcodeInputFilter=whitespace?
> 
> It looks like we worked on an out-of-date master branch... (this line was
> added 10 days ago).
> 
> We must try to reproduce the bug on master (bug 26351)

"(bug 26351)" was added on the wrong line. It's the bug that was pushed 10 days ago.
Why can't we edit comments ?? :)
Comment 11 Jérémy Breuillard 2021-10-18 10:18:03 UTC
Bug tested on master branch. It works correctly.
Comment 12 Julian Maurice 2021-10-18 11:40:32 UTC
Problem still exists in 21.05 and lower versions.
The attached patches should work correctly on those versions. I will squash them for an easier review
Comment 13 Julian Maurice 2021-10-18 11:46:29 UTC
Created attachment 126430 [details] [review]
[21.05] Bug 22204: Use barcodedecode in additem.pl

Test plan:
1. Set syspref itemBarcodeInputFilter to 'whitespace'
2. Create an item with barcode "1"
3. Try to create an item with barcode "   1   " and verify that it is
   blocked
4. Create an item with barcode "  XXXXX  " and verify that it is saved
   without spaces in database:
   SELECT barcode FROM items WHERE barcode LIKE '%XXXXX%'

Co-authored-by: Jérémy Breuillard <jeremy.breuillard@biblibre.com>
Comment 14 David Nind 2021-11-07 23:11:52 UTC
Patch no longer applies 8-(... (using koha-testing-docker and 21.05):

126430 - [21.05] Bug 22204: Use barcodedecode in additem.pl

Apply? [(y)es, (n)o, (i)nteractive] y
Applying: Bug 22204: Use barcodedecode in additem.pl
Using index info to reconstruct a base tree...
M	cataloguing/additem.pl
Falling back to patching base and 3-way merge...
Auto-merging cataloguing/additem.pl
CONFLICT (content): Merge conflict in cataloguing/additem.pl
error: Failed to merge in the changes.
Patch failed at 0001 Bug 22204: Use barcodedecode in additem.pl
Comment 15 Fridolin Somers 2022-04-28 02:53:35 UTC

*** This bug has been marked as a duplicate of bug 30409 ***