Bug 19721 - Tabulation in the description of a patron category breaks the patron search. Cause: tabs must be escaped in JSON
Summary: Tabulation in the description of a patron category breaks the patron search. ...
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: Main
Hardware: All All
: P5 - low major (vote)
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-30 13:44 UTC by Victor Grousset/tuxayo
Modified: 2020-11-30 21:45 UTC (History)
3 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Victor Grousset/tuxayo 2017-11-30 13:44:18 UTC
=== Reproduce ===
1. Go to staff: /cgi-bin/koha/admin/categories.pl
2. Edit a category with existing patrons
3. Add a tab in the description
   here is one to copy for convenience: "	"
4. Save the category
5. Go to /cgi-bin/koha/members/members-home.pl
6. Filters → Category → select the just edited one
7. Hit search, just below
8. Then you should see "Processing..."
   As if the request was still running forever

=== Cause ===
In the browser dev tools, we can see that the XRH request to "search" actually comes back.
The response seems normal.
Except that Firefox warns "SyntaxError: JSON.parse: bad control character in string literal at line 23 column 29 of the JSON data"
Which points to our tab.
Which invalidates the JSON: https://stackoverflow.com/questions/19799006/unable-to-parse-tab-in-json-files#19799355

> The whitespace characters are: character tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and space (U+0020).
> Whitespace is not allowed within any token, except that space is allowed in strings.

=== Workaround ===
Remove the tab from the description of the category.
In /cgi-bin/koha/admin/categories.pl
One can use the filter in the table (called search).
And search for a tab "	" to get the "corrupted" ones.


=== Fix ===
It seems that we should escape the tabs (and CRs(\r) and LFs(\n))
Or just get rid of them.

Another question is where?
- Where the category form is processed?
  - early in the upper layers? (when the request just comes)
  - or in the lower layers? (if the category is managed by the ORM)
- In the database itself with a trigger?
- Other ideas?

=== Going further ===
How to find which other bugs like this one might cause hard to diagnose issues?
Comment 1 Owen Leonard 2019-11-19 12:55:56 UTC
This appears to have been fixed. I can't reproduce the problem.