Bug 41617 - itemsearch.pl produces wrong CSV
Summary: itemsearch.pl produces wrong CSV
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low major
Assignee: Tomás Cohen Arazi (tcohen)
QA Contact: Testopia
URL:
Keywords:
Depends on: 40880
Blocks:
  Show dependency treegraph
 
Reported: 2026-01-14 18:37 UTC by Tomás Cohen Arazi (tcohen)
Modified: 2026-01-14 22:10 UTC (History)
3 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 41617: Remove extra spaces breaking CSV formatting (6.50 KB, patch)
2026-01-14 19:02 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi (tcohen) 2026-01-14 18:37:05 UTC
I've been following the CSV generation code in Koha for security reasons, and didn't notice this particular case until now.

This script generates CSV using... templates instead of Text::CSV.

Besides the fact this is wrong, there's a bug in the generated CSV. Bug 40880 solved an issue with the headers, but the produced file contains things like this:

```
"First field", "Second, field", "Third"
```

the extra space after the comma makes it get interpreted like:

```
First field
<space>"Second
<space>field"
<space>"Third"
```
Comment 1 Tomás Cohen Arazi (tcohen) 2026-01-14 19:02:08 UTC
Created attachment 191439 [details] [review]
Bug 41617: Remove extra spaces breaking CSV formatting

This patch removes extra spaces breaking CSV parsing in tools like Excel.

To test:
1. Perform an item search selecting the CSV option
2. Open the CSV with a TEXT EDITOR of your choice
=> FAIL: Notice the extra spaces after the commas (those used as separators, no the ones within the double quotes)
3. Apply this patch
4. Repeat 1-2
=> SUCCESS: No extra spaces!
5. Sign off :-D

Note: On the first attempt you can open the file on Excel if you have it and notice things are not aligned.
Note2: Using double quotes on all fields regardless of the context works for most parsers, but is not correct CSV. Will deal with it on a separate bug.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>