Every time a value containing an "&" is rendered, upon page refresh, another "amp&;" is added to the value; in effect, it's duplicating itself.

I attempted to implement a solution I'd found on here for allowing "&" in an autocomplete searchbar instead of "amp&;". As seen below in the code, I added .replace(/&/g, '&'); onto the end of the line 15 .replace(/\"/g, '"').replace(/\\/g, '\')

Needless to say, it's not working -- any insight would be appreciated.

(function ($) {
var pluses = /\+/g;
function encode(s) {
    return config.raw ? s : encodeURIComponent(s);
function decode(s) {
    return config.raw ? s : decodeURIComponent(s);
function stringifyCookieValue(value) {
    return encode(config.json ? JSON.stringify(value) : String(value));
function parseCookieValue(s) {
    if (s.indexOf('"') === 0) {
        // This is a quoted cookie as according to RFC2068, unescape...
        s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\').replace(/&/g, '&');
    try {
        // Replace server-side written pluses with spaces.
        // If we can't decode the cookie, ignore it, it's unusable.
        // If we can't parse the cookie, ignore it, it's unusable.
        s = decodeURIComponent(s.replace(pluses, ' '));
        return config.json ? JSON.parse(s) : s;
    } catch(e) {}
  • are you trying to implement a solution for a bug in SharePoint? Or is this a custom autocomplete that you are trying to fix by writing this? – Mike Jul 1 '16 at 19:45
  • Thanks for the response. It's a custom autocomplete that works fine, except for the "amp&;" issue. Would it help to see another part of the script? Do you know why this wouldn't be working? – TheJDScott Jul 1 '16 at 20:33

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.