Bug 21035 - runreport.pl prints only a newline when printing a row that has a field that contains an embedded newline
Summary: runreport.pl prints only a newline when printing a row that has a field that ...
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: master
Hardware: All All
: P5 - low minor (vote)
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-03 21:21 UTC by Barton Chittenden
Modified: 2018-09-21 12:11 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Bot Control: ---
When did the bot last check this:
Who signed the patch off:
Text to go in the release notes:


Attachments
Bug 21035: Handle new lines when running reports (1.35 KB, patch)
2018-07-04 18:07 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 21035: Handle new lines when running reports (1.43 KB, patch)
2018-07-13 19:44 UTC, Maryse Simard
Details | Diff | Splinter Review
Bug 21035: Handle new lines when running reports (1.49 KB, patch)
2018-08-02 11:36 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Barton Chittenden 2018-07-03 21:21:49 UTC
when runrepurt.pl is run using the --format=csv or --format=tsv options, any fields which contain embedded newlines will cause the row of results to be blank, displaying only a newline.

To replicate:

1) Choose two items, say barcode '123' and '456'
2) Change the public note on 123 to read

Line1
Line2

(I.e. type 'Line1', then press Enter, type 'Line2' and click update).
3) Change the public note on 456 to read

Public note has one and only one line.

Click update.
4) Create a report with the followng query:

select barcode, itemnotes from items where barcode in ( '123', '456' )

Let's say that this is report number 10.

5) run ./misc/cronjobs/runreport.pl --format=csv 10: 

$ perl ./misc/cronjobs/runreport.pl --format=csv 9

456,"Public note has one and only one line."

The same results hold when using --format=tsv

When using --format=html, both rows are displayed:

$ perl ./misc/cronjobs/runreport.pl --format=html 10
<table><tr><td>123</td> <td>Line1
Line2</td></tr>
<tr><td>456</td> <td>Public note has one and only one line.</td></tr>
Comment 1 Jonathan Druart 2018-07-04 18:07:10 UTC
Created attachment 76698 [details] [review]
Bug 21035: Handle new lines when running reports

See https://metacpan.org/pod/Text::CSV_XS#Embedded-newlines

Test plan:

1) Choose two items, say barcode '123' and '456'
2) Change the public note on 123 to read

Line1
Line2

(I.e. type 'Line1', then press Enter, type 'Line2' and click update).
3) Change the public note on 456 to read

Public note has one and only one line.

Click update.
4) Create a report with the followng query:

select barcode, itemnotes from items where barcode in ( '123', '456' )

Let's say that this is report number 10.

5) run ./misc/cronjobs/runreport.pl --format=csv REPORT_ID:

=> You should see both lines
Comment 2 Maryse Simard 2018-07-13 19:44:44 UTC
Created attachment 76964 [details] [review]
Bug 21035: Handle new lines when running reports

See https://metacpan.org/pod/Text::CSV_XS#Embedded-newlines

Test plan:

1) Choose two items, say barcode '123' and '456'
2) Change the public note on 123 to read

Line1
Line2

(I.e. type 'Line1', then press Enter, type 'Line2' and click update).
3) Change the public note on 456 to read

Public note has one and only one line.

Click update.
4) Create a report with the followng query:

select barcode, itemnotes from items where barcode in ( '123', '456' )

Let's say that this is report number 10.

5) run ./misc/cronjobs/runreport.pl --format=csv REPORT_ID:

=> You should see both lines

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Followed the test plan and it works.
Comment 3 Katrin Fischer 2018-08-02 11:36:28 UTC
Created attachment 77425 [details] [review]
Bug 21035: Handle new lines when running reports

See https://metacpan.org/pod/Text::CSV_XS#Embedded-newlines

Test plan:

1) Choose two items, say barcode '123' and '456'
2) Change the public note on 123 to read

Line1
Line2

(I.e. type 'Line1', then press Enter, type 'Line2' and click update).
3) Change the public note on 456 to read

Public note has one and only one line.

Click update.
4) Create a report with the followng query:

select barcode, itemnotes from items where barcode in ( '123', '456' )

Let's say that this is report number 10.

5) run ./misc/cronjobs/runreport.pl --format=csv REPORT_ID:

=> You should see both lines

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Followed the test plan and it works.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 4 Nick Clemens 2018-08-09 12:25:47 UTC
Awesome work all!

Pushed to master for 18.11
Comment 5 Martin Renvoize 2018-08-10 07:48:12 UTC
Pushed to 18.05.x for 18.05.03
Comment 6 Fridolin SOMERS 2018-09-21 12:11:17 UTC
Pushed to 17.11.x for 17.11.10