For SharePoint 2013 Search REST api, for the query text parameter values, what is the best way to encode all possible characters that would result in a syntax error, in javascript?

So far I came up with this:

    this.getSafeRestSearchValue = function(parameterValue) {
        return parameterValue.replace(/ /g, "+").replace(/'/g, "''");           

Does anyone know if this is right and would account for all cases?

And what if the value has a + in it (not meant to be a space, but actually a plus sign), how would I make it not encoded?


  • Have you try to use regex (Regular expresion)? – LR2007_ITA94 Sep 13 '16 at 12:49
  • Its not the technique for replacing I'm concerned about, its more about what specific characters to replace and to replace with what. – omega Sep 13 '16 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.