Bug 40569 - Quotation marks in series fields (490/830) break XSLT search links in Elasticsearch
Summary: Quotation marks in series fields (490/830) break XSLT search links in Elastic...
Status: Failed QA
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Slava Shishkin
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-31 17:41 UTC by Slava Shishkin
Modified: 2026-01-14 07:42 UTC (History)
3 users (show)

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


Attachments
Bug 40569: Escape quotation marks in series fields in XSLT search links (3.65 KB, patch)
2025-07-31 17:52 UTC, Slava Shishkin
Details | Diff | Splinter Review
Bug 40569: Escape quotation marks in series fields in XSLT search links (Elasticsearch) (3.77 KB, patch)
2025-08-11 13:10 UTC, Slava Shishkin
Details | Diff | Splinter Review
Hi, (3.81 KB, patch)
2025-09-05 19:00 UTC, Noah Tremblay
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Slava Shishkin 2025-07-31 17:41:44 UTC
Search links generated from series fields in the XSLT detail view (MARC 440a/490a/830a) fail when the series title contains quotation marks ("), due to the lack of escaping in the generated URL.

Steps to reproduce:
1. Create or edit a bibliographic record (better more than one)
2. In field 490$a or 830$a, enter a series name with quotes, e.g., Test "Series"
3. Save the record
4. On the detail page, click the Series link (generated from the XSLT view) Series: Test "Series"
5. The search fails or returns an error due to a malformed query
Comment 1 Slava Shishkin 2025-07-31 17:52:51 UTC Comment hidden (obsolete)
Comment 2 Bernard 2025-08-08 14:13:24 UTC
Strangely this works fine for me without any fix using test plan. 25.06.00.002 using Chrome 138.0.7204.184. Maybe different browsers are less forgiving? Rendered url that results is cgi-bin/koha/catalogue/search.pl?q=se,phr:%22Test%20%22Series%22%22
Comment 3 Slava Shishkin 2025-08-11 12:33:40 UTC
Thanks, Bernard, for checking!

My apologies, I forgot to mention that this only happens when SearchEngine = Elasticsearch — with Zebra, it works fine.

The issue is not browser-specific. Without escaping, the generated ES query contains raw quotes:

se,phr:"Test "Series""

In this case, Koha returns in the browser:

No results found  
No results match your search for '"se,phr:"Test "Series"""'.

With the patch, quotes are escaped, and the query becomes:

se,phr:"Test \"Series\""
Comment 4 Slava Shishkin 2025-08-11 13:10:25 UTC
Created attachment 185309 [details] [review]
Bug 40569: Escape quotation marks in series fields in XSLT search links (Elasticsearch)

1. Choose Elasticsearch like Search engine: cgi-bin/koha/admin/preferences.pl?op=search&searchfield=SearchEngine
2. Create or edit a bibliographic record (beter more then one)
3. In field 490$a or 830$a, enter a series name with quotes, e.g. Test "Series"
4. Save the record
5. On the detail page, click the Series link (generated from the XSLT view)Series: Test "Series"
6. The search fails or returns an error due to malformed query
7. Apply the patch
8. Reload the bibliographic detail page
9. Click the Series link again
10. The search should return matching records
Comment 5 Bernard 2025-08-13 14:25:43 UTC
Hi Slava,

I replicated it this time with elastic :)

Your patch works fine! Does it also need to be on line 490 of MARC21slimUtils.xsl which also has se,phr ?

Also it would be great to add to the OPAC xslt too where I think we have the same issue.

/kohadevbox/koha/koha-tmpl/opac-tmpl/bootstrap/en/xslt/MARC21slimUtils.xsl
lines are 381, 406, 454 and 505.

thanks

Bernard
Comment 6 Noah Tremblay 2025-09-05 19:00:06 UTC
Created attachment 186245 [details] [review]
Hi,

It works fine for me as well.  
I’m not changing the status since I also find Bernard’s suggestion interesting.  

Signed-off-by: noah <noah@inlibro.com>
Comment 7 Katrin Fischer 2026-01-14 07:42:32 UTC
1) QA checks - all pass!

2) Code review

I don't believe this is the right fix. It adds quoting, but it removed the URL encoding that I believe is also needed:

-                    <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=se,phr:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
+                    <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=se,phr:<xsl:call-template name="quote_search_term">
+                        <xsl:with-param name="term"><xsl:value-of select="marc:subfield[@code='a']"/></xsl:with-param>
+                    </xsl:call-template>
+                </xsl:attribute>

quote_search_term only adds " and escapes quotes in the string. Hope I am not missing something.

3) Other

I notice that the sign-off line for Noah could be a little nicer :)

Signed-off-by: noah <noah@inlibro.com>

Added assignee.