In XQuery 3.1 (under eXist-db 4.4) I receive search requests to the a controller where I create a parameter docset from the URL's query string text:
else if (starts-with(lower-case($exist:path), "/search")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/search.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="docset"
value="{search:search-term-cleaner(request:get-parameter("text","norequest"))}"/>
<add-parameter name="pagetype" value="search"/>
</forward>
</view>
</dispatch>
I clean any incoming such requests to /search?text="" to permit only certain characters into the search query:
declare function search:search-term-cleaner($text as xs:string?) as xs:string?
{
let $cleanterm := replace($text,'[^A-Za-z\+*0-9]', '')
return $cleanterm
};
There are two problems, under two slightly different scenarios:
- If the request comes in
/search?text=some%+textthe site complains with
org.eclipse.jetty.http.BadMessageException: 400: Unable to parse URI query java.lang.IllegalArgumentException: Not valid encoding '%+t'
- If the request comes in
/search?text=some+text, the controller passes throughsometextwithout the permitted+sign
Googling this has not lead me to a solution, but I am not experienced in managing HTTP parsing and may not understand the problem enough to search for the solution.
This is via local host http://localhost:8081/exist/apps/.