pnp / PnP-Tools

Scripts and tools for Office 365 and SharePoint - More for IT Pro's

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search query tool doesn't works with single quote in query

stevebeauge opened this issue · comments

Version of SQT : 2.8.6.1 (side note: the app reports 2.8.6.0 although the zip file is 2.8.6.1.zip...)
OS: Win 10 2004
Target: SP Online

I want to perform some searches that contains a ' but the search fails.

Exemple: search for it's working fails.

Using GET verb:

   "error": {
        "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
        "message": {
            "lang": "fr-FR",
            "value": "La cha\u00eene de requ\u00eate \u00ab\u00a0querytext\u00a0\u00bb est manquante ou incorrecte."
        }
    }

Which can be translated into querystring parameter 'querytext' is missing or incorrect.

I guess this is due to an incorrect escaping of the parameter, because the url is :

https://mycorp.sharepoint.com/sites/mysite/_api/search/query?querytext='It's+working'

As you can see, the single quote isn't escaped.

Using POST verb.

 "error": {
        "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
        "message": {
            "lang": "fr-FR",
            "value": "Le flux JSON n\u2019est pas correctement format\u00e9."
        }
    }

Translation : json feed isn't properly formatted.

Again, I guess this is due a incorrect formatting of the value. The raw query contains :

	{'request': { 'Querytext':'It's working'} }

Again, the single isn't escaped.

Search doesn't index quotes anyways, but I'll add it as an improvement point to escape the user query.

I'm not sure what's behind the scene, but I observe that querying with managed props where "exact match" is set to on, single quotes are taken into account.

Basically, this query works in my browser and returns expected data:

https://mycorp.sharepoint.com/sites/mysite/_api/search/query?querytext='devdebugOWSTEXT:"It''s+working"'

@stevebeauge no one uses that, do they 😁 but fair point.