Search code examples
htmlweburlencodeopensearchopensearchdescription

forward slashes in searchTerms break search url in opensearch.xml


My opensearch XML looks something like below.

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
  xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>my site short name</ShortName>
  <Description>My search description</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Image width="16" height="16" type="image/x-icon">
    https://somesite.com/images/icons/favicon-16x16.png
  </Image>
  <Url type="text/html" method="get"
    template="https://somesite.com/search/{searchTerms}/page/1"></Url>
</OpenSearchDescription>

The problem that I face here is that, if the keyword is something like 'this/that', the URL that is submitted to my site becomes

https://somesite.com/search/this/that/page/1

but the searchTerms should have been url encoded to something like,

https://somesite.com/search/this%2fthat/page/1

Due the URL now having extra forward slashes from the search keys, the search URL is broken for my application.

For my application accepting search params is not an option. This would violate the consistency of other pages similar to search by keywords.

Is there a way I can handle this in the opensearch.xml itself?


Solution

  • As per the opensearch specification

    The "searchTerms" parameter

    Replaced with the keyword or keywords desired by the search client.

    Restrictions: The value must be URL-encoded.

    For now, I raised this bug against Chromium project to get this fixed as it seems to be that the chrome is not encoding the search parameters.