I use JS to create a CAML query. When it is generated, it looks like this:
@v1 = {"ViewXml":"<View Scope='RecursiveAll'><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef
Name='Designation'/><FieldRef Name='srd_title2'/></ViewFields><Query><Where><Contains><FieldRef Name
='Subject'/>My Value Here<Value Type='Note'>
When users attempt to search using values such as "My Hand\Number2" or "Body & Styles", I receive errors such as "An unrecognized escape sequence '\' was found in a JSON string value". I changed the code to do a manual replacement (e.g., param.replace("\\","\\\\")
, and that worked for back slashes. But is there a good way to make sure I'm checking for all of these? I tried using CDATA such as in this example: https://sharepoint.stackexchange.com/a/11703/24039 to no avail.
update: I actually used val.(/\\/g, "\\\\")
as Wrapping "val" in encodeURI or encodeURIComponent is not working for this case. I didn't realize the double \ became escaped when I submitted the question, so I wrapped it in a code block now. Sorry for the confusion.