Bug 20334 - Option for escaping slashes in search queries
Summary: Option for escaping slashes in search queries
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching - Elasticsearch (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: David Gustafsson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-05 12:49 UTC by David Gustafsson
Modified: 2018-04-25 19:15 UTC (History)
2 users (show)

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


Attachments
Bug 20334 - Option for escaping slashes in search queries (12.78 KB, patch)
2018-03-05 13:10 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 20334 - Option for escaping slashes in search queries (12.78 KB, patch)
2018-03-05 13:20 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 20334 - Option for escaping slashes in search queries (10.45 KB, patch)
2018-03-06 14:01 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 20334 - Option for escaping slashes in search queries (10.48 KB, patch)
2018-03-14 09:02 UTC, Nicolas Legrand
Details | Diff | Splinter Review
Bug 20334 - Option for escaping slashes in search queries (10.53 KB, patch)
2018-03-23 20:01 UTC, Maksim Sen
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Gustafsson 2018-03-05 12:49:20 UTC
There are a number of reserved characters in the Elasticsearch query syntax (+ - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /). Slash (/), which is used for regexps, is quite often used in searches with the intent as it should be interpreted as a literal sting. This causes the search to crash since Elasticsearch treats this as an unclosed regular expression (or a regexp if two slashes are used which can be even more confusing). To address this particular case here is a patch with an option to escape slashes (or require them to be escaped to count as a regular expression delimiter).
Comment 1 David Gustafsson 2018-03-05 13:10:38 UTC
Created attachment 72434 [details] [review]
Bug 20334 - Option for escaping slashes in search queries

Add "QueryRegexEscapeOption" system preference to provide option to escape
Elasticsearch regexp delimiters (/) within queries, or alternativly to
unescape escaped slashes (\/) while escaping unescaped slashes, in
effect making "\/" the new regexp delimiter.

How to test:
1) Run tests in ./t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t
2) All tests should succeed
Comment 2 David Gustafsson 2018-03-05 13:20:52 UTC
Created attachment 72435 [details] [review]
Bug 20334 - Option for escaping slashes in search queries

Add "QueryRegexEscapeOption" system preference to provide option to escape
Elasticsearch regexp delimiters (/) within queries, or alternativly to
unescape escaped slashes (\/) while escaping unescaped slashes, in
effect making "\/" the new regexp delimiter.

How to test:
1) Run tests in ./t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t
2) All tests should succeed
Comment 3 Josef Moravec 2018-03-05 16:32:25 UTC
David, is this ready for testing? If so, please change status to "Needs signoff"
Comment 4 David Gustafsson 2018-03-06 10:25:34 UTC
Ok! Yes, ready to signoff.
Comment 5 David Gustafsson 2018-03-06 10:29:50 UTC
Just saw that a swap file was accidentally committed, setting failed until this is fixed (later today).
Comment 6 David Gustafsson 2018-03-06 14:01:15 UTC
Created attachment 72471 [details] [review]
Bug 20334 - Option for escaping slashes in search queries

Add "QueryRegexEscapeOption" system preference to provide option to escape
Elasticsearch regexp delimiters (/) within queries, or alternativly to
unescape escaped slashes (\/) while escaping unescaped slashes, in
effect making "\/" the new regexp delimiter.

How to test:
1) Run tests in ./t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t
2) All tests should succeed
Comment 7 Nicolas Legrand 2018-03-14 09:02:28 UTC
Created attachment 72830 [details] [review]
Bug 20334 - Option for escaping slashes in search queries

Add "QueryRegexEscapeOption" system preference to provide option to escape
Elasticsearch regexp delimiters (/) within queries, or alternativly to
unescape escaped slashes (\/) while escaping unescaped slashes, in
effect making "\/" the new regexp delimiter.

How to test:
1) Run tests in ./t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t
2) All tests should succeed

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
Comment 8 Maksim Sen 2018-03-23 20:01:44 UTC
Created attachment 73222 [details] [review]
Bug 20334 - Option for escaping slashes in search queries

Add "QueryRegexEscapeOption" system preference to provide option to escape
Elasticsearch regexp delimiters (/) within queries, or alternativly to
unescape escaped slashes (\/) while escaping unescaped slashes, in
effect making "\/" the new regexp delimiter.

How to test:
1) Run tests in ./t/Koha/SearchEngine/ElasticSearch/QueryBuilder.t
2) All tests should succeed

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
Signed-off-by: Maksim Sen <maksim.sen@inlibro.com>
Comment 9 Katrin Fischer 2018-04-22 10:53:53 UTC
Hi David, please remember to assign bugs to yourself when you work on them and provide patches!
Comment 10 David Gustafsson 2018-04-25 19:15:14 UTC
Ok, done :)